仅使用加法在 c 中创建减法和除法
我通过减法创建了除法,但无法通过加法算出来
int divide, divis, quotient;
printf("Enter Number 1:");
scanf("%d", ÷);
printf("Enter Number 2:");
scanf("%d", &divis);
quotient=0;
while(divide > 0){
divide = divide - divis;
quotient++;
}
printf("%d\n, quotient);
I have created division through subtraction but i cannot figure it out through addition
int divide, divis, quotient;
printf("Enter Number 1:");
scanf("%d", ÷);
printf("Enter Number 2:");
scanf("%d", &divis);
quotient=0;
while(divide > 0){
divide = divide - divis;
quotient++;
}
printf("%d\n, quotient);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要从
除
开始并减去直到低于0,而是从0开始并加直到超过除
。请注意,您需要小心不要超出数字范围。
Instead of starting from
divide
and subtracting until you drop below 0, instead start from 0 and add until you exceeddivide
.Note that you will need to be careful that you don't overflow your number range.
如果你已经有了除法,你可以将减数除以-1,然后加上被减数。
If you already have division, you can just divide the subtrahend by -1 and then add the minuend.