Software & Finance





C Programming (Turbo C++ Compiler) Fahrenheit to Celsius Converter





I have given here C Program source code to convert Fahrenheit to Celsius and Celsius to Fahrenheit.

 

The forumula for conversion is given below:

 

Celsius = (Fahrenheit - 32) * 5 / 9;

Fahrenheit = Celsius * (9 / 5) + 32;

 


Source Code


// FahrenheitCelsiusConverter.cpp : Implementation File
 

#include <stdio.h>

 

int main()

{

    double val;

    printf("Enter a number to use in Fahrenheit and Celsius Converter: ");

    scanf("%lf", &val);

 

    double Celsius = (val - 32.0) * 5.0 / 9.0;

    double Fahrenheit = (val * (9.0 / 5.0) + 32);

 

    printf("\n%8.4lf %cF = %8.4lf %cC\n", val, 248, Celsius,  248);

    printf("%8.4lf %cC = %8.4lf %cF\n\n", val, 248, Fahrenheit,  248);

 

      return 0;

}

Output


Enter a number to use in Fahrenheit and Celsius Converter: 100

 

100.0000 °F =  37.7778 °C

100.0000 °C = 212.0000 °F

 

Press any key to continue . . .

 

 

 

Enter a number to use in Fahrenheit and Celsius Converter: -40

 

-40.0000 °F = -40.0000 °C

-40.0000 °C = -40.0000 °F

 

Press any key to continue . . .

 

 

 

Enter a number to use in Fahrenheit and Celsius Converter: 0

 

  0.0000 °F = -17.7778 °C

  0.0000 °C =  32.0000 °F

 

Press any key to continue . . .

 

 

   

Enter a number to use in Fahrenheit and Celsius Converter: 28

 

 28.0000 °F =  -2.2222 °C

 28.0000 °C =  82.4000 °F

 

Press any key to continue . . .