結(jié)果是0.000000,為什么?
#include <stdio.h>
int main()
{
? ? int a,b,c,d;
? ? double result;
? ? a = 1;
? ? b = 2;
? ? c = 3;
? ? d = 4;
? ? result = a/ ?b/ ?c ?/d; ? ?//在這里體驗(yàn)哦~
? ? printf("%f\n", result);
? ? return 0;
}
#include <stdio.h>
int main()
{
? ? int a,b,c,d;
? ? double result;
? ? a = 1;
? ? b = 2;
? ? c = 3;
? ? d = 4;
? ? result = a/ ?b/ ?c ?/d; ? ?//在這里體驗(yàn)哦~
? ? printf("%f\n", result);
? ? return 0;
}
2016-06-15
舉報(bào)
2016-11-10
因?yàn)閕nt定義的是整型,a/b即1/2取整為0,再一直除下去還是0,最后以浮點(diǎn)型輸出就變成了0.000000
2016-06-15
#include <stdio.h>
int main()
{
? ? int a,b,c,d;//將這里的int 改成double,結(jié)果就有了。
? ? double result;
? ? a = 1;
? ? b = 2;
? ? c = 3;
? ? d = 4;
? ? result = a/ ?b/ ?c ?/d; ? ?//在這里體驗(yàn)哦~
? ? printf("%f\n", result);
? ? return 0;
}
2016-06-15
看到下一節(jié)課就明白了。。。。。。
2016-06-15
1/2/3/4= 0.041666, 為什么上述代碼輸出結(jié)果是0?如何修改代碼能得到0.041666?