Temperature conversion
In this tutorial, we will study the conversion of temperature. We use a different unit of temperature conversions and we learn C Program to convert Fahrenheit to Celsius and Fahrenheit to Kelvin.
Different temperature units are Celsius, Fahrenheit, Kelvin. there is a different formula for converting these value to the specified unit. which are as follow :
Temperature conversion formula
1. Fahrenheit ( F ) :
Celsius
the formula used for converting Fahrenheit to Celsius
(F-32) * 5/9;
Kelvin ( Fahrenheit to Kelvin formula )
the formula used for converting Fahrenheit to kelvin is as follow,
(F – 32) * 5/9 +273.15
2. Celsius ( C ) :
Fahrenheit
a formula used for converting Celsius to Fahrenheit formula (c to f)
(C * 9/5)+32
Kelvin
a formula used for converting celsius to kelvin formula
C + 273.15
3. Kelvin ( K ) :
Fahrenheit : (kelvin to Fahrenheit formula)
a formula used for converting kelvin to Fahrenheit is as follow,
( K – 273.15 ) * 9/5 + 32
Celsius : ( kelvin to Celsius conversion)
the formula used for converting kelvin to Celsius ( kelvin to celsius formula)
K – 273.15
we have all formulas to convert into specified unit now we will implement the program to perform these conversions.
C Program to convert Fahrenheit to Celsius and Fahrenheit to Kelvin
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 | #include<stdio.h>void main(){int from ,to ;float value;printf(“temperature conversion \n”);printf(“Enter no of unit to convert from : \n 1.Celsius \n2.Fahrenheit \n 3. kelvin\n”);scanf(“%d”,&from);printf(“Enter no of unit to convert to : \n 1. Celsius \n2.Fahrenheit \n 3. kelvin\n”);scanf(“%d”,&to);printf(“Enter the value to convert:”);scanf(“%d”,&value);/* converting given value from specified unit to kelvin */switch(from){case 1:value=value + 273.15;break;case 2:value = (value + 459.67 )* 5/9;break;case 3:break;default:break;}/* Converting value from kelvin to specified value */switch(to){case 1:value=value + 273.15;break;case 2:value = (value) * 9/ 5-459.67;break;case 3:break;default:break;}printf(“converted value = %d “, value);} |

Output :
Temperature conversion
Enter no of a unit to convert from :
- Celsius
- Fahrenheit
- kelvin
1
Enter no of a unit to convert from :
- Celsius
- Fahrenheit
- kelvin
2
Enter the value to convert :
40
Converted value = 103.999992
Fahrenheit to Celsius and Fahrenheit to Kelvin