Average of three
Add three values and divide. An easy embedded C problem (Variables and operators), run and graded in the browser.
easy · Variables and operators · arithmetic · division
Return the average of a, b and c.
All the values are whole numbers, so the division throws away any fraction. The average of 1, 2 and 2 is 1.
Starter code
int average3(int a, int b, int c) {
return 0;
}Example tests
An exact average
printf("%d\n", average3(3, 6, 9));Expected output:
6The fraction is dropped
printf("%d\n", average3(1, 2, 2));Expected output:
1Learn it first
- Variables and operators · Storing values, doing arithmetic, comparing, and the two surprises of integer maths.
More Variables and operators problems
- Last digit · Use the remainder operator.
- Celsius to Fahrenheit · Fix a formula that divides too early.
- 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.