0

I have following C program, that takes a temperature in Fahrenheit and convert in to Celsius value. But, every time I input a value it always gives me0.00 as output. I'm not understanding where is the problem.

#include <stdio.h>
int main()

{
    float cel_out, fht_in;

    printf("Enter a temperature in farenheit: ");
    scanf("%f", &fht_in);
    cel_out = (fht_in - 32) * (5/9);
    printf("Temperature in celcious: %.2f", cel_out);

    return 0;
}
opu 웃
  • 464
  • 1
  • 7
  • 22

1 Answers1

2

In this euqation

cel_out = (fht_in - 32) * (5/9);

When you use 5/9 it is integer data type which results 0. so

 cel_out = (fht_in - 32) * 0; 

Results 0 only!

You need to use-

cel_out = (fht_in - 32) * (5.0f/9.0f); 

here it is treated as float values and gives the actual result of 5/9.

Sathish
  • 3,740
  • 1
  • 17
  • 28