C |数据类型|问题3

预测产量

null

#include <stdio.h>
int main()
{
float c = 5.0;
printf ( "Temperature in Fahrenheit is %.2f" , (9/5)*c + 32);
return 0;
}


(A) 华氏温度为41.00度 (B) 华氏温度是37.00度 (C) 华氏温度为0.00 (D) 编译错误 答复: (B) 说明: 由于9和5是整数,整数运算发生在子表达式(9/5)中,我们得到1作为其值。

为了修复上面的程序,我们可以用9.0代替9,或者用5.0代替5,这样就可以进行浮点运算。

#include <stdio.h>
int main()
{
float c = 5.0;
printf ( "Temperature in Fahrenheit is %.2f" , (9.0/5)*c + 32);
return 0;
}


这个问题的小测验

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享