a program will calculate and print the average of five posti
a program will calculate and print the average of five postive numbers read from keyboard design the flowchart for this problem
Solution
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int n = 5;
int sum = 0;
int value;
for(int i=0; i<n; i++){
cout<<\"Enter the value \"<<(i+1)<<\": \";
cin >> value;
sum = sum + value;
}
double average = sum/(double)n;
cout<<\"Average is \"<<average<<endl;
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter the value 1: 1
Enter the value 2: 2
Enter the value 3: 3
Enter the value 4: 4
Enter the value 5: 5
Average is 3
