Challenge: Average of Three
Completed
Read three whole numbers and print their average with exactly 2 decimal places.
Input
Three integers separated by spaces.
Output
One line: Average: and the average, like Average: 3.67.
Example
Input
2 4 5
Output
Average: 3.67
Editor
C++
Hints
(a + b + c) / 3 is integer division! Divide by 3.0 instead.
#include <iomanip> and use fixed << setprecision(2).
Solution explanation
Dividing by 3.0 makes it a decimal division. fixed + setprecision(2) always shows two decimal places.
Show solution
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
double average = (a + b + c) / 3.0;
cout << fixed << setprecision(2) << "Average: " << average << "\n";
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