将华氏度转换为摄氏度的 C 程序总是打印零 [英] C program to convert Fahrenheit to Celsius always prints zero

查看:24
本文介绍了将华氏度转换为摄氏度的 C 程序总是打印零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些关于在 C 中将华氏温度转换为摄氏温度的程序的帮助.我的代码如下所示

I 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:



");
    scanf("%d", &fahrenheit);
    celsius = (5 / 9) * (fahrenheit - 32);
    printf("The converted temperature is %lf
", 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆