Here is a C++ program find sum and average of array elements
SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
int a[20],n,sum=0;
cout<<"How many elements to be stored (max 20) : ";
cin>>n;
cout<<"Enter elements ";
for(int i=0;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
cout<<"Sum of elements : "<<sum;
cout<<"\nAverage : "<<float(sum/4);
return 0;
}
using namespace std;
int main()
{
int a[20],n,sum=0;
cout<<"How many elements to be stored (max 20) : ";
cin>>n;
cout<<"Enter elements ";
for(int i=0;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
cout<<"Sum of elements : "<<sum;
cout<<"\nAverage : "<<float(sum/4);
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment