代码一:
#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 );
}