ZKX's LAB

两个数求余数的代码 如何求两个数的余数

2021-04-23知识11

用C语言编写(计算两个整数的和、 差、积、商与余数 代码一:includeint main(void){int num1,num2;scanf(\"%d%d\",&num1,&num2);printf(\"%d+d=d\\n\",num1,num2,num1+num2);printf(\"%d-%d=d\\n\",num1,num2,num1-num2);printf(\"%d*%d=d\\n\",num1,num2,num1*num2);if(num2)printf(\"%d/d=g\\n\",num1,num2,(double)num1/num2);else printf(\"ERROR,DIV BY ZERO\\n\");printf(\"%d%d=d\\n\",num1,num2,num1%num2);return 0;}代码二:2113includevoid main(){int x,y;printf(\"please enter a,b,c:\");scanf(\"%d,%d\",&x,&y);printf(\"\\nx+y=d\\n\",x+y);printf(\"x-y=d\\n\",x-y);printf(\"x*y=d\\n\",x*y);printf(\"x/y=d\\n\",x/y);printf(\"x%y=d\\n\",x%y);}下图为5261C语言算术运算符:扩展资料:4102算术运算符实例:includemain(){int a=21;int b=10;int c;c=a+b;printf(\"Line 1-c 的值1653是%d\\n\",c);c=a-b;printf(\"Line 2-c 的值是%d\\n\",c);c=a*b;printf(\"Line 3-c 的值是%d\\n\",c);c=a/b;printf(\"Line 4-c 的值是%d\\n\",c);c=a%b;printf(\"Line 5-c 的值是%d\\n\",c);c=a+;printf(\"Line 6-c 的值是%d\\n\",c);c=a-;printf(\"Line 7-c 的值是%d\\n\",c);}

键盘输入两个数,求两数相除的余数,把这两个数分别加上、减去这个余数之后的结果 includeint main(){int x,y,z;printf(\"Input 2 words\\n\");printf(\"First:\");scanf(\"%d\",&x);printf(\"Second:\");scanf(\"%d\",&y);z=x%y;printf(\"%d\\t%d\\n\",(x+z),(x-z));printf(\"%d\\t%d\\n\",(y+z),(y-z));return 0;}

C语言中如何求任意两数的余数 用%求余数,但是求余只能是整数是语言的求余符号比如99对2求余可以写成 99%2

#两个数求余数的代码

随机阅读

qrcode
访问手机版