Simvik

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:

212

Freezing point

printf("%d\n", to_fahrenheit(0));

Expected output:

32

Learn it first

More Variables and operators problems