C program to convert temperature from Fahrenheit to Celsius
In this program, you will take Fahrenheit input from the user, and you will convert the temperature from Fahrenheit to Celsius in 3 different ways.
Logic
- take Fahrenheit temperature from the user.
- conerting Fahrenheit to Celsius by using formula: celsius=(fahrenheit – 32)*5/
- print Celsius value.
Convert Fahrenheit to Celsius in C
#include <stdio.h>
int main()
{
// declare variable
float celsius,Fahrenheit;
// take input temperature in fahrenheit
printf("\nEnter temperature in Fahrenheit:");
scanf("%f",&fahrenheit);
// convert Fahrenheit to celsius
celsius=(fahrenheit - 32)*5/9;
// Print the result in celsius
printf("\ntemperature in Celsius = %f",celsius);
return 0;
}
output
Enter temperature in Fahrenheit:100 temperature in Celsius = 37.777779
C program to convert temperature from Fahrenheit to Celsius using function
#include <stdio.h>
float fahrenheitTOcelsius(float);
int main()
{
// declare variable
float celciusresult,fahrenheit;
// take input temperature in fahrenheit
printf("\nEnter temperature in Fahrenheit:");
scanf("%f",&fahrenheit);
//call fahrenheitTOcelsius function
celciusresult=fahrenheitTOcelsius(fahrenheit);
// Print the result in celsius
printf("\ntemperature in Celsius is= %f",celciusresult);
return 0;
}
// it will return celsius value
float fahrenheitTOcelsius(float fahrenheit)
{
float celsius;
// convert Fahrenheit to celsius
celsius=(fahrenheit - 32)*5/9;
return celsius;
}
output
Enter temperature in Fahrenheit:200 temperature in Celsius is= 93.333336
temperature from Fahrenheit to Celsius using pointer
#include <stdio.h>
int main()
{
// declare variable
float celsius,fahrenheit,*f;
// take input temperature in Fahrenheit
printf("\nEnter temperature in Fahrenheit:");
scanf("%f",&fahrenheit);
// pass the address of fahrenheit value into f variable
f=&fahrenheit;
// convert Fahrenheit to celsius
celsius=(*f - 32)*5/9;
// Print the result in celsius
printf("\nCelsius value = %f",celsius);
return 0;
}
output
Enter temperature in Fahrenheit:250 Celsius value = 121.111115