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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用C语言编写(计算两个整数的和、 差、积、商与余数相关的知识,希望对你有一定的参考价值。

题目是
程序填空,不要改变与输入输出有关的语句。
输入2个整数 num1 和 num2,计算并输出它们的和、差、积、商与余数。
输出两个整数的余数可以用 printf("%d %% %d = %d\n", num1, num2, num1%num2);
输入输出示例:括号内是说明
输入
5 3 (num1=5,num2=3)
输出
5 + 3 = 8
5 - 3 = 2
5 * 3 = 15
5 / 3 = 1
5 % 3 = 2

#include <stdio.h>
int main(void)

int num1, num2;

/*---------*/


/*-----------*/写什么???/

代码一:

#include <stdio.h>

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 <stdio.h>

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 <stdio.h>

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


参考技术A #include <stdio.h>
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;
本回答被提问者采纳
参考技术B #include <stdio.h>
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);
printf("%d / %d = %d\n", num1, num2, num1/num2);
printf("%d %% %d = %d\n", num1, num2, num1%num2);

return 0;
参考技术C #include <stdio.h>
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);
printf("%d / %d = %d\n", num1, num2, num1/num2);
printf("%d % %d = %d\n", num1, num2, num1%num2);

return 0;
参考技术D #include<stdio.h>

#include<math.h>

void main()



int a,b;

long h,c,j,s,y;

printf("a=");

scanf("%d",&a);

printf("b=");

scanf("%d",&b);

h=a+b;

j=a*b;

c=a-b;

s=a/b;

y=a%b;

printf("h=%d c=%d j=%d s=%d y=%d\n",h,c,j,s,y);

getch();

JS写一个简单的程序,输入两个整数,打印这两个数的和,差,积,余数

<!DOCTYPE html>

<html>

 <head>

<meta charset="UTF-8">

<title></title>

</head>

 <body>

<input type="test"  id="n1" value="" />

<input type="test"  id="n2" value="" />

<input type="submit"  id="d1" value="count"   onclick="result()"/>

</body>

<script>

function result(){

var a1=document.getElementById("n1");

var a2=document.getElementById("n2");

var b1=Number(a1.value)+Number(a2.value);

var b2=Number(a1.value)-Number(a2.value);

var b3=Number(a1.value)*Number(a2.value);

var b4=Number(a1.value)%Number(a2.value);

 

alert("And"+b1+"\n"+"Difference"+b2+"\n"+"Product"+b3+"\n"+"Remainder"+b4)

 

}

</script>

 

</html>

以上是关于用C语言编写(计算两个整数的和、 差、积、商与余数的主要内容,如果未能解决你的问题,请参考以下文章

编写程序,输入两个整数num1和num2,计算并输出他们的和,差,积,商与余数

输入2个整数 num1 和 num2,计算并输出它们的和、差、积、商与余数。

用c语言设计一个计算两个整数的和、差、积、商、和余数的程序

如何编写程序,输入俩个整数num1和num2,计算并输出它们的的和,差,积,商,与余数

C语言程序设计:输入两个整数,计算并输出它们的和、积、差、商和余数各是多少?

C语言 求大神改成正确的 题目是:输入两个整数num1和num2,计算并输出它们的和、差、积、商和余数