Challenge: Exact Average
Completed
Read three whole numbers and print their average with 2 decimals.
Input
Three integers.
Output
Average: X.XX
Example
Input
1 2 4
Output
Average: 2.33
Editor
C
Hints
Dividing by 3 (an int) would cut off the decimals.
Divide by 3.0, or use a (double) cast.
Solution explanation
Using 3.0 makes it a decimal division, so the answer keeps its decimal part.
Show solution
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
printf("Average: %.2f\n", (a + b + c) / 3.0);
return 0;
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module