【发布时间】:2011-02-03 19:02:51
【问题描述】:
我需要一些关于在 C 中将华氏温度转换为摄氏度的程序的帮助。我的代码如下所示
#include <stdio.h>
int main(void)
{
int fahrenheit;
double celsius;
printf("Enter the temperature in degrees fahrenheit:\n\n\n\n");
scanf("%d", &fahrenheit);
celsius = (5 / 9) * (fahrenheit - 32);
printf("The converted temperature is %lf\n", celsius);
return 0;
}
每次我执行它,结果都是 0.000000。我知道我错过了一些东西,但不知道是什么。
【问题讨论】:
-
您正在使用整数,您需要使用浮点数或双精度数。
-
旁注,编译器通常认为 5.0 是双倍的。您必须说 5.0f 才能进行浮点值计算。似乎与移动更相关
标签: c