【发布时间】:2021-11-18 07:51:55
【问题描述】:
#include <stdio.h>
int main()
{
int num1, num2;
printf ("Input value for num1: ");
scanf ("%d", &num1);
printf ("Input value for num2: ");
scanf ("%d", &num2);
int prod =0, i;
for(i = 1; i <= num1; i++){
prod += num2;
}
int quo = 0 , rem = 0;
for(rem = num1 - num2; rem >= 0; rem = rem-num2) {
if(rem < 0)
break;
else
quo++;
}
//The last part is that i need to find the remainder without using multiplication, division and the modulo itself.
printf ("The product of %d and %d is: %d\n", num1, num2, prod);
printf ("The integer quotient of %d and %d is: %d\n", num1, num2, quo);
return 0;
}
【问题讨论】:
-
而且,我真的不知道该怎么做。我希望有人能帮助我。
-
您忘记告诉我们发布代码的问题
-
余数为
rem + num2 -
提示:10 除以 3 为 3,其余为 1。10 - 3 = 7。7 - 3 = 4。4 - 3 = 1。现在 1 小于 3,1 是休息。
-
注意
if(rem < 0) break; else是不必要的,它重复了循环条件rem >= 0。