Photo by Xavier Coiffic on Unsplash
A Simple program to convert the temperature from Celsius to Fahrenheit to Kelvin in C
#include<stdio.h>
int main()
{
printf("Enter the 1 for Celsius to fahrenheit \n 2 for Fahrenheit to Celsius \n and 3 for Kelvin to Celsius\n");
int opt=0;
scanf("%d",&opt);
switch(opt){
case 1:float tem;
printf("Enter temperature in Celsius\n");
scanf("%f",&tem);
float a1=(tem*9/5)+32;
printf("Temp=%f\n",a1);
break;
case 2:float temp1;
printf("Enter temperature in Fahrenheit\n");
scanf("%f",&temp1);
float a2=(temp1-32)*9/5;
printf("Temp=%f\n",a2);
break;
case 3:float temp2;
printf("Enter temperature in Kelvin\n");
scanf("%f",&temp2);
float a3=temp2-273.15;
printf("Temp%f\n",a3);
break;
default:
printf("Wrong entry");
break;
}
return 0;
}
To convert Fahrenheit to Celsius we use the formula (32°F − 32) × 5/9 = 0°C.
And To convert from Celsius to Fahrenheit we use the formula (0°C × 9/5) + 32 = 32°F.
And Kelvin to Celsius we use K-273.15.
Thanks ...