C程序华氏转换为摄氏
问题描述:
我正在写一个程序的一类,我在和需要一些帮助与程序在华氏C.转换为摄氏我的code看起来像这样
I'm writing a program for a class I'm in and need some help with a program for converting Fahrenheit to Celsius in C. My code looks like this
#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。我知道我失去了一些东西,但无法弄清楚什么。
Every time I execute it it the result is 0.000000. I know I'm missing something but can't figure out what.
答
5/9会导致整数除法,这将= 0
5/9 will result in integer division, which will = 0
尝试 5.0 / 9.0
代替。