Tuesday, 17 June 2014

C++ program to find the Average of n numbers



Here is a C++ program to find the Average of n numbers


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    int a[50],sum=0,n;
    float avg;
    cout<<"How many numbers to be entered ";
    cin>>n;
    cout<<"Enter the numbers ";
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    avg=sum/(n*1.0);
    cout<<"Average = "<<avg;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment