Skip to content
Exercise · Variables and types · lesson 10 of 10

Exercise: Fahrenheit

Write a function func toFahrenheit(c float64) float64 that converts a temperature from degrees Celsius to degrees Fahrenheit by the formula F = C × 1.8 + 32.

  • toFahrenheit(100) → 212
  • toFahrenheit(-40) → -40
  • toFahrenheit(36.6) → 97.88

Constraints: the temperature is not below absolute zero (−273.15 °C), and the result is compared with the expected one to within 1e-9, that is, 0.000000001.

Do not add extra imports unless the task says so explicitly.

fahrenheit.go — go
go · 6 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way