Skip to content
Exercise · Operators · lesson 9 of 9

Exercise: average of three

Write a function func average(a, b, c int) float64 that returns the arithmetic mean of three integers, fractional part included.

  • average(1, 2, 3) → 2
  • average(1, 2, 2) → 1.6666666666666667
  • average(-1, -2, -4) → -2.3333333333333335

Constraints: the numbers are from -1000 to 1000 and may be negative; the result is compared with a tolerance of 1e-9.

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

average.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