Home / Programs / Write C a program that uses a function to convert a temperature from Fahrenheit scale to Celsius scale.
Programming Example

Write C a program that uses a function to convert a temperature from Fahrenheit scale to Celsius scale.

👁 1,207 Views
💻 Practical Program
📘 Step by Step Learning
Write C a program that uses a function to convert a temperature from Fahrenheit scale to Celsius scale.

Program Code

#include <stdio.h>

float FtoC(float); 

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

/* FUNCTION DEFINITION */

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

Output


 Temperature in Fahrenheit scale: -40
-40.000000 Fahrenheit equals -40.000000 Celsius

 

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.