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

是用C语言,谢谢
2024-12-31 23:02:11
推荐回答(5个)
回答1:

编写程序有许多语言,假设是C语言吧

#include

int main(int argc,char **argv)
{
int num1,num2;
int n1;/*和*/
int n2;/*差*/
int n3;/*积*/
int n4;/*商*/
int n5;/*余*/

printf("请输入整数num1=?");
scanf("%d",&num1);
printf("请输入整数num2=?");
scanf("%d",&num2);

n1 = num1 + num2;
n2 = num1 - num2;
n3 = num1 * num2;
n4 = num1 / num2;
n5 = num1 % num2;

printf("和=%d\n",n1);
printf("差=%d\n",n2);
printf("积=%d\n",n3);
printf("商=%d (整除商)\n",n4);
printf("商=%f (浮点商)\n",(double)(num1/num2));
printf("余=%d\n",n5);

}

回答2:

#include
using namespace std;
int main()
{
int num1,num2;
cout<<"输入两个整数:"<cin>>num1>>num2;
cout<<"和:"<cout<<"差:"<cout<<"积:"<cout<<"商:"<<(double)num1/num2<cout<<"余数:"<return 0;
}

回答3:

#include
main()
{ int num1,num2;
int x,y,z,k,j;
print("num1=",num1);
print("num2=",num2);

x=num1+num2;
y=num1-num2;
z=num1*num2;
k=num1/num2;
j=num1%num2;

print("和=",x);
print("差=",y);
print("积=",z);
print("商=",k);
print("余=",j);

}

回答4:

#include "stdio.h"
void main()
{
int num1,num2;
int he,cha,ji,yu;
float shan;
printf("input the two number:");
scanf("%d%d",&num1,&num2);
he=num1+num2;
cha=num1-num2;
ji=num1*num2;
yu=num1%num2;
shan=1.0*num1/num2;
printf("he : %d\n",he);
printf("cha : %d\n",cha);
printf("ji : %d\n",ji);
printf("yu shu : %d\n",yu);
printf("shan : %f\n",shan);

}

回答5:

#include
int
main()
{
int
x=12,
y=10;
printf("x+y=%d\n",
x+y);
printf("x-y=%d\n",
x-y);
printf("x*y=%d\n",
x*y);
printf("x/y=%f\n",
x*1.0/y);
printf("x%%y=%d\n",
x%y);
return
0;
}
或者把中间的那段输出语句改成这样的也一样:
printf("x+y=%d\nx-y=%d\nx*y=%d\nx/y=%f\nx%%y=%d\n",
x+y,
x-y,
x*y,
x*1.0/y,
x%y);