Ad space (banner)
🔧C Lessons
Lesson 66 / 68

Converting Temperature (Celsius to Fahrenheit)

This lesson covers converting between Celsius and Fahrenheit in C, so you can practice translating a unit-conversion formula into code. It's for anyone searching "C Celsius Fahrenheit conversion."

Converting Celsius (°C) to Fahrenheit (°F) uses the formula "°C × 9/5 + 32," and going the other way uses "(°F − 32) × 5/9." Unit conversion is a classic programming exercise.

The example provides two functions, celsiusToFahrenheit() and fahrenheitToCelsius(), each following its respective formula. You can confirm 25°C correctly converts to 77°F, and 77°F correctly converts back to 25°C.

A common early mistake is the order of operations in the formula. Getting the order of multiplication, division, and addition wrong in c * 9 / 5 + 32 produces an incorrect result, so you need to understand the formula's meaning before translating it into code.

It's a simple formula, but also a good exercise in translating a plain equation directly into code. Even a special value like absolute zero (-273.15°C) can be handled with the exact same formula.

📖 Reference code
✍️ Your code
Type your code, then press "Run"

🧪 This site can't compile or run C directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser — nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)