C程序华氏转换为摄氏 [英] C program to convert Fahrenheit to Celsius
本文介绍了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
代替。
这篇关于C程序华氏转换为摄氏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文