习题5:编写一个程序显示求模运算的结果,把用户输入的第1个整数作为求模运算符的第2个运算对象,该数在运算过程中保持不变,用户输入的后一个数是第1个运算对象,当用户输入一个非正值时程序结束。
代码:
#include<stdio.h>
int main(){
int foperand,soperand;
printf("Enter an integer to serve as the sencond operand: ");
scanf("%d",&soperand);
printf("Now enter the first operand: ");
scanf("%d",&foperand);
while(foperand>0){
printf("%d %% %d is %d\n",foperand,soperand,foperand%soperand);
printf("Enter next number for first operand(<=0 to quit): ");
scanf("%d",&foperand);
}
printf("Done");
return 0;
}