用C语言编写(计算两个整数的和、 差、积、商与余数

2020-07-15 社会 892阅读

代码一:

#include 

int 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;

}

代码二:

#include

void 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);

}

下图为C语言算术运算符:

扩展资料:

算术运算符实例:

#include

main()

{

int a = 21;

int b = 10;

int c ;

c = a + b;

printf("Line 1 - c 的值是 %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 );

}

声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com