> 其他 >
C语言 求大神改成正确的 题目是:输入两个整数num1和num2,计算并输出它们的和、差、积、商和余数
#include
int main(void)
{ int num1,num2;
int x,y,z,k,j;
print("Enter num1=",num1);
scanf("%d",&num1);
print("Enter num2=",num2);
scanf("%d",&num2);
x=num1+num2;
y=num1-num2;
z=num1*num2;
k=num1/num2;
j=num1%num2;
print("num1+num2=x",x);
print("num1-num2=y",y);
print("num1*num2=z",z);
print("num1/num2=k",k);
print("num1%num2=j",j);
return 0;
}
我上C语言就4节课 新手
我把下面改成printf("num1+num2=%d",x);
printf("num1-num2=%d",y);
printf("num1*num2=%d",z);
printf("num1/num2=%d",k);
printf("num1%num2=%d",j);
提醒成功编译,但有警告信息.
xfc2_6.c: In function ‘main’:
xfc2_6.c:5: warning: too many arguments for format
xfc2_6.c:7: warning: too many arguments for format
xfc2_6.c:18: warning: format ‘%n’ expects type ‘int *’, but argument 2 has type ‘int’
xfc2_6.c:18: warning: too few arguments for format
有什么要改的吗? 谢谢
额 最后格式还要这样的
Enter num1:5
Enter num2:3
5+3=8
5-3=2
5*3=15
5/3=1.67
5%3=2
人气:323 ℃ 时间:2020-03-07 13:31:47
解答
print改成printf就可以了
标准答案 拿去吧 除法进行的Int型的除法 自己懂得
#include
int main(void)
{ int num1,num2;
int x,y,z,k,j;
printf("Enter num1=");
scanf("%d",&num1);
printf("Enter num2=");
scanf("%d",&num2);
x=num1+num2;
y=num1-num2;
z=num1*num2;
k=num1/num2;
j=num1%num2;
printf("num1+num2=%d\n",x);
printf("num1-num2=%d\n",y);
printf("num1*num2=%d\n",z);
printf("num1/num2=%d\n",k);
printf("num1%%num2=%d\n",j);
return 0;
}如果除法要保留2位呢那么num1 num2就得是double 但是 你的num1%num2 要求的是int型 所以不能改你只是求商嘛余数后面有求所以没必要用double
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版