Sum and average of array elements in C++

#include<iostream>

using namespace std;

int main()

{

int n,a[5];

int avg=0,sum=0;

cout<<"the array elemenys are";

for(int i=0;i<5;i++)

{

cin>>a[i];

sum=sum+a[i];

}

cout<<"\nthe sum of array is : "<<sum;

avg=sum/5;

cout<<"\nthe average of array elements are : "<<avg;

return 0

}

output:
the array elemenys are 5
9
6
5
7

the sum of array is : 32
the average of array elements are : 6

Comments