题目:8.编写一个程序, 显示求模运算的结果。 把用户输入的第1个整数作为求模运算符的第2个运算对象, 该数在运算过程中保持不变。 用户后面输入的数是第1个运算对象。 当用户输入一个非正值时, 程序结束。 其输出示例如下:
This program computes moduli.
Enter an integer to serve as the second operand: 256
Now enter the first operand: 438
438 % 256 is 182
Enter next number for first operand (<= 0 to quit): 1234567
1234567 % 256 is 135
Enter next number for first operand (<= 0 to quit): 0
Done
#include<stdio.h>
int main()
{ //循环求模程序
int num,num_ed; //声明整数和被求模整数
printf("This program computes moduli.\n");
printf("Enter an integer to serve as the second operand:");
scanf("%d",&num_ed);
printf("Now enter the first operand:");
scanf("%d",&num);
while(num > 0)
{
printf("%d %% %d = %d\n",num,num_ed,num%num_ed);
printf("Enter next number for first operand \
(<= 0 to quit):");
scanf("%d",&num);
}
printf("Done");
return 0;
}
}
运行结果:以256,438,1234567,0为例
备注:自己写的,也可能有问题,大家一起交流呀