要除以2的数字并得到如下结果:
5/2 = 2.50
但它仅输出2。
我现在不是我做错了。
这是我的代码:
int a;
int b;
int c;
printf("First num\n");
scanf("%d", &a);
printf("Second num\n");
scanf("%d", &b);
c = a / b;
printf("%d", c);
您需要一个double
变量来存储结果。int
仅存储整数。此外,在执行除法操作之前,还必须转换其他变量。
做这样的事情
double c;
.
.
.
c = (double)a / (double)b;
printf("%f", c);
笔记:
您不需要&
inprintf()
语句。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句