Saturday, September 7, 2013

C++ Program to find the average of given numbers with output

#include<iostream>
using namespace std;
int main(){
int n,i,a[50];
float average,total=0;
cout<<"Enter the total number of elements(max 50)";
cin>>n;
for(i=0;i<n;i++){
    cout<<"Enter the "<<i+1<<" number:";
    cin>>a[i];
}
for(i=0;i<n;i++){
    total=a[i]+total;
}
average=total/n;
cout<<"The sum of the given numbers is "<<total<<endl;
cout<<"The average is "<<average;
return 0;
}

Output:-


No comments:

Post a Comment

Ads Inside Post