In this program, the user is ask to enter 5 integer elements that will save in array arr. Then we calculate the sum and average of these number display it on console.
#include<iostream>
using namespace std;
int main()
{
int arr[5], i, sum = 0;
double avg;
cout<<"Enter 5 array students\n";
/* Input marks of 10 students */
for(i=0; i<5; i++)
cin>>arr[i];
/* Logic to calculate sum and average*/
for(i=0; i<5; i++)
{
sum = sum + arr[i];
}
avg = sum / 5;
/* Print sum */
cout<<"\nSum = "<<sum;
cout<<"\nAverage = "<<avg;
return 0;
}
Enter 5 array students
4 2 5 8 6
Sum = 25
Average = 5