C program to convert temperature from degree celsius to fahrenheit


In this example, you will the concept of c program to convert degree Celsius to Fahrenheit.

C program to convert degree Celsius to Fahrenheit

Mathematical formula for temperature conversion

F = ( 1.8 * C) + 32

Where,

  • F = Temperature in Fahrenheit
  • C = Temperature in degree Celsius

We can simply convert temperature using the above formula.

Remember to use floating type variables for calculation.

If you don’t know already about floating point data types in C programming, we recommend you to go through C programming data types.

C program to convert degree Celsius to Fahrenheit

#include<stdio.h>

int main()
{
 float fahr, cel;
 printf("Enter the temperature in celsius: ");
 scanf("%f", &cel);

 fahr = (1.8 * cel) + 32.0; //temperature conversion formula
 printf("\nTemperature in Fahrenheit: %.2f F\n", fahr);

 return 0;
}

Output

Enter the temperature in Celsius: 40
Temperature in Fahrenheit: 104.00 F

You can convert degree Celsius to Fahrenheit online to check whether or not the program generated correct output.

Explanation

We have used float type variable for Celsius and Fahrenheit.

.2f is used to display temperature up to two decimal places.