Temperature Conversion of Celsius, Fahrenheit and Kelvin
Posted on 9:40 PM by Azailg
How to do a Temperature Conversion of Celsius, Fahrenheit and Kelvin.
Below is the codes for converting Celsius to Fahrenheit, Celsius to Kelvin, Fahrenheit to Celsius, Fahrenheit to Kelvin, Kelvin to Fahrenheit and Kelvin to Celsius.
#include < stdio.h >
main()
{
int a;
float c,f,k;
char choice;
start:
printf("Temperature Convertion\n");
printf("1. Celsius to Fahrenheit\n");
printf("2. Celsius to Kelvin\n");
printf("3. Fahrenheit to Celsius\n");
printf("4. Fahrenheit to Kelvin\n");
printf("5. Kelvin to Celsius\n");
printf("6. kelvin to Fahrenheit\n");
printf("Enter ur choice:");
scanf("%d",&a);
switch(a)
{
case 1:
{
printf("\t\t\tCelsius to Fahrenheit\n");
printf("Enter Celsius Temperature to be converted:: ");
scanf("%f",&c);
f=(1.8*c)+32;
printf("The Fahrenheit temperature is %f\n",f);
printf("Do you want to try another operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 2:
{
printf("\t\t\tCelsius to Kelvin\n");
printf("Enter Celsius Temperature to be converted: ");
scanf("%f",&c);
k=c+273.15;
printf("The Kelvin temperature is %f\n",k);
printf("Do you want to try another operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 3:
{
printf("\t\t\tFahrenheit to Celsius\n");
printf("Enter Fahrenheit Temperature to be converted: ");
scanf("%f",&f);
c=(f-32)/1.8;
printf("The Celsius temperature is %f\n",c);
printf("Do you want to try another operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 4:
{
printf("\t\t\tFahrenheit to kelvin\n");
printf("Enter Fahrenheit Temperature to be converted: ");
scanf("%f",&f);
c=(f-32)/1.8;
k=c+273.15;
printf("The Kelvin temperature is %f\n",k);
printf("Do you want to try another operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 5:
{
printf("\t\t\tKelvin to Celsius\n");
printf("Enter Kelvin Temperature to be converted: ");
scanf("%f",&k);
c=k-273.15;
printf("The Celsius temperature is %f\n",c);
printf("Do you want to try another operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 6:
{
printf("\t\t\tKelvin to Fahrenheit\n");
printf("Enter Kelvin Temperature to be converted: ");
scanf("%f",&k);
c=k-273.15;
f=(1.8*c)+32;
printf("The Fehrenheit temperature is %f\n",f);
printf("Do you want to try another operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
}
}
main()
{
int a;
float c,f,k;
char choice;
start:
printf("Temperature Convertion\n");
printf("1. Celsius to Fahrenheit\n");
printf("2. Celsius to Kelvin\n");
printf("3. Fahrenheit to Celsius\n");
printf("4. Fahrenheit to Kelvin\n");
printf("5. Kelvin to Celsius\n");
printf("6. kelvin to Fahrenheit\n");
printf("Enter ur choice:");
scanf("%d",&a);
switch(a)
{
case 1:
{
printf("\t\t\tCelsius to Fahrenheit\n");
printf("Enter Celsius Temperature to be converted:: ");
scanf("%f",&c);
f=(1.8*c)+32;
printf("The Fahrenheit temperature is %f\n",f);
printf("Do you want to try another operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 2:
{
printf("\t\t\tCelsius to Kelvin\n");
printf("Enter Celsius Temperature to be converted: ");
scanf("%f",&c);
k=c+273.15;
printf("The Kelvin temperature is %f\n",k);
printf("Do you want to try another operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 3:
{
printf("\t\t\tFahrenheit to Celsius\n");
printf("Enter Fahrenheit Temperature to be converted: ");
scanf("%f",&f);
c=(f-32)/1.8;
printf("The Celsius temperature is %f\n",c);
printf("Do you want to try another operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 4:
{
printf("\t\t\tFahrenheit to kelvin\n");
printf("Enter Fahrenheit Temperature to be converted: ");
scanf("%f",&f);
c=(f-32)/1.8;
k=c+273.15;
printf("The Kelvin temperature is %f\n",k);
printf("Do you want to try another operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 5:
{
printf("\t\t\tKelvin to Celsius\n");
printf("Enter Kelvin Temperature to be converted: ");
scanf("%f",&k);
c=k-273.15;
printf("The Celsius temperature is %f\n",c);
printf("Do you want to try another operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
case 6:
{
printf("\t\t\tKelvin to Fahrenheit\n");
printf("Enter Kelvin Temperature to be converted: ");
scanf("%f",&k);
c=k-273.15;
f=(1.8*c)+32;
printf("The Fehrenheit temperature is %f\n",f);
printf("Do you want to try another operation? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
break;
}
}
}
0 comments:
Post a Comment