🚀⚡Beginner
Calculate Fahrenheit to Celsius
Temperature conversion program
This program converts temperature from Fahrenheit to Celsius by applying the conversion formula. For example, 82°F is equal to 27.7°C.
📐 Formula to Convert Fahrenheit to Celsius
T(°C) = (T(°F) - 32) × 5/9T(°C): Temperature in Celsius
T(°F): Temperature in Fahrenheit
📋 Algorithm
- Define temperature in Fahrenheit units
- Apply the formula to convert Fahrenheit to Celsius
- Print the temperature in Celsius
Program to Convert Fahrenheit to Celsius
fahrenheit_to_celsius.c
C
1// C Program to convert2// Fahrenheit to Celsius3#include <stdio.h>45// Function to convert Degree6// Fahrenheit to Degree Celsius7float fahrenheit_to_celsius(float f)8{9 return ((f - 32.0) * 5.0 / 9.0);10}1112// Driver code13int main()14{15 float f = 40;1617 // Passing parameter to function18 printf("Temperature in Degree Celsius : %0.2f",19 fahrenheit_to_celsius(f));20 return 0;21}Output
Temperature in Degree Celsius : 4.44
Program with User Input
fahrenheit_celsius_input.c
C
1#include <stdio.h>23int main()4{5 float fahrenheit, celsius;6 7 // Get temperature in Fahrenheit from user8 printf("Enter temperature in Fahrenheit: ");9 scanf("%f", &fahrenheit);10 11 // Convert to Celsius using formula12 celsius = (fahrenheit - 32) * 5.0 / 9.0;13 14 // Display the result15 printf("%.2f°F = %.2f°C\n", fahrenheit, celsius);16 17 return 0;18}$ ./fahrenheit_celsius
Enter temperature in Fahrenheit: 98.6\n98.60°F = 37.00°C
📖 Code Explanation
| Code | Explanation |
|---|---|
| float f = 40; | Declare and initialize Fahrenheit temperature |
| (f - 32.0) | Subtract 32 from Fahrenheit value |
| * 5.0 / 9.0 | Multiply by 5/9 to get Celsius |
| %0.2f | Format specifier for 2 decimal places |
| 5.0 / 9.0 | Use float division (not 5/9 which gives 0) |
⚠️ Why use 5.0/9.0 instead of 5/9?
In C, 5/9 performs integer division and returns 0! Using 5.0/9.0 ensures floating-point division which gives the correct result 0.5556.
🔄 Step-by-Step Calculation
Converting 40°F to Celsius:
Step 1: Subtract 32 → 40 - 32 = 8
Step 2: Multiply by 5 → 8 × 5 = 40
Step 3: Divide by 9 → 40 ÷ 9 = 4.44°C
📊 Common Temperature Conversions
| Fahrenheit | Celsius | Significance |
|---|---|---|
| 32°F | 0°C | Freezing point of water |
| 68°F | 20°C | Room temperature |
| 98.6°F | 37°C | Human body temperature |
| 212°F | 100°C | Boiling point of water |
⚡ Complexity Analysis
Time Complexity
O(1)
Space Complexity
O(1)
🎯 Key Takeaways
✓Formula: °C = (°F - 32) × 5/9
✓Use float division (5.0/9.0)
✓32°F = 0°C (Freezing point)
✓212°F = 100°C (Boiling point)
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials