C语言乘法错在哪里
答案:3 悬赏:20 手机版
解决时间 2021-03-05 02:03
- 提问者网友:聂風
- 2021-03-04 04:56
C语言乘法错在哪里
最佳答案
- 五星知识达人网友:忘川信使
- 2021-03-04 06:20
修改后的代码:
#include
int main (void)
{
int feet, fathoms;
fathoms = 2;
feet = 6 * fathoms;
printf("There are %d feet in %d fathoms!
", feet, fathoms);
printf("Yes, I said %d feet!
", 6*fathoms);
return(0);
}追问那能帮我看看这里面有什么错吗?
#include
int main(void)
{
int a;
a = 1;
int b;
b = a * 5;
printf("b=%d\n", b);
return(0);
}追答上面已经帮你修改了,再发一次:
#include
int main (void)
{
int feet, fathoms;
fathoms = 2;
feet = 6 * fathoms;
printf("There are %d feet in %d fathoms!
", feet, fathoms);
printf("Yes, I said %d feet!
", 6*fathoms);
return(0);
}运行效果:
#include
int main (void)
{
int feet, fathoms;
fathoms = 2;
feet = 6 * fathoms;
printf("There are %d feet in %d fathoms!
", feet, fathoms);
printf("Yes, I said %d feet!
", 6*fathoms);
return(0);
}追问那能帮我看看这里面有什么错吗?
#include
int main(void)
{
int a;
a = 1;
int b;
b = a * 5;
printf("b=%d\n", b);
return(0);
}追答上面已经帮你修改了,再发一次:
#include
int main (void)
{
int feet, fathoms;
fathoms = 2;
feet = 6 * fathoms;
printf("There are %d feet in %d fathoms!
", feet, fathoms);
printf("Yes, I said %d feet!
", 6*fathoms);
return(0);
}运行效果:
全部回答
- 1楼网友:怀裏藏嬌
- 2021-03-04 07:33
把printf("There are %d feet in %d fathoms!"\n中的\n放到"前面。
- 2楼网友:醉吻情书
- 2021-03-04 06:45
严格来讲,你的代码是错误的,用int的b接收double型的a的计算结果,是不可以的,即使结果是整数。结果当然也会出现误差。正确的应该是:doublea=10.3845;doubleb;b=10000*a;printf("%lf",b);补充:把上面printf("%lf",b);改为printf("%.0lf",b);就能使后面无小数。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯