Celsius to Fahrenheit
Fix a formula that divides too early. An easy embedded C problem (Variables and operators), run and graded in the browser.
easy · Variables and operators · arithmetic · division
The formula is F = C × 9 / 5 + 32. The starter code has it written down, yet it returns wrong values. Run it, then work out why.
Return the temperature in Fahrenheit, with any fraction dropped.
Starter code
int to_fahrenheit(int c) {
return c * (9 / 5) + 32;
}Example tests
Boiling point
printf("%d\n", to_fahrenheit(100));Expected output:
212Freezing point
printf("%d\n", to_fahrenheit(0));Expected output:
32Learn it first
- Variables and operators · Storing values, doing arithmetic, comparing, and the two surprises of integer maths.
More Variables and operators problems
- Average of three · Add three values and divide.
- Last digit · Use the remainder operator.
- Time in seconds · Combine several values into one total.
- Even or odd · Produce a yes-or-no answer as 1 or 0.
- Operator precedence · Fix an expression that is evaluated in the wrong order.
- Percentage · Keep precision by ordering the operations correctly.
- Does it fit in a byte? · Combine two comparisons with a logical operator.