预测产量
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