C program for temperature conversion from Fahrenheit scale to Celsius scale

      This program does temperature conversion of Fahrenheit scale to celsius scale using conversion formula i.e., C = (5/9) (F-32) where
‘C’ is the temperature in centigrade and
‘F’ is the temperature in Fahrenheit.

temperature conversion program in c



Source Code :

#include<stdio.h>
float FtoC(float); 

int main(void)
{
	float tempInF;
	float tempInC;
	printf("\n Temperature in Fahrenheit scale: ");
	scanf("%f", &tempInF);             //Step 1
	tempInC = FtoC(tempInF);           // Step 2
	printf("%f Fahrenheit equals %f Celsius \n", tempInF,tempInC); //Step 4
	return 0;
}

/* FUNCTION DEFINITION */

float FtoC(float faren) 
{
	float factor = 5.0/9.0;
	float freezing = 32.0;
	float celsius;
	celsius = factor*(faren - freezing);  //Step 3
	return celsius;
}


edit-code-image

Sample Test cases:

1.  Temperature in Fahrenheit scale: 32
    32.000000 Fahrenheit equals 0.000000 Celsius

2.  Temperature in Fahrenheit scale: 94.38
   94.379997 Fahrenheit equals 34.655556 Celsius

3.  Temperature in Fahrenheit scale: 100
   100.000000 Fahrenheit equals 37.777779 Celsius

Explanation:

Step 1: Temperature in Fahrenheit scale is read from the user using scanf() function.

Step 2: Then function is called from the main program.

Step 3: The conversion factor is used to find temperature in celsius for corresponding temperature in Fahrenheit.

Step 4: The converted temperature is printed on the output screen using printf() function.

More Insights:

1. How conversion factor is derived ?

More Content :Explore More