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 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;
} 
                        

🖥 Program Output


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

 
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.