1.7 用加法实现乘除减运算

1. 7 Write a method to implement *, - , / operations. You should use only the + operator.

直接贴答案吧。。

With an understanding of what each operation (minus, times, divide) does, this problem can
be approached logically.


»» Subtraction should be relatively straightforward, as we all know that a - b is the same thing as a + (-1)*b.


»» Multiplication: we have to go back to what we learn in grade school: 21 * 3 = 21 + 21 + 21. It’s slow, but it works.


»» Division is the trickiest, because we usually think of 21 / 3 as something like “if you divide
a 21 foot board into 3 pieces, how big is each piece?” If we think about if the other way
around (eg, the reciprocal), it’s a little easier: “I divided a 21 foot board in x pieces and
got pieces of 3 feet each, how many pieces were there?” From here, we can see that if we
continuously subtract 3 feet from 21 feet, we’ll know how many pieces there are. That is,
we continuously subtract b from a and count how many times we can do that.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值