Programming Example
C Program to convert temperature from fahrenheit to celsius
Study this program carefully to understand the logic, output, and explanation in a structured way.
/**
* C program to convert temperature from degree fahrenheit to celsius
*/
#include"stdio.h"
int main()
{
float celsius, fahrenheit;
// Reads temperature in fahrenheit
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &fahrenheit);
// Fahrenheit to celsius conversion formula
celsius = (fahrenheit - 32) * 5 / 9;
// Print the result
printf("%.2f Fahrenheit = %.2f Celsius \n", fahrenheit, celsius);
return 0;
}
Enter temperature in Fahrenheit: -40
-40.00 Fahrenheit = -40.00 Celsius
Press any key to continue . . .
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.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.