Sunday, 4 January 2015

Cpp Program to find the Average of N numbers


This is a Cpp program  to find average of N  numbers.
Generally average  is calculated as the sum of all the numbers divided by total numbers.

Average = (n1+n1+.........)/N


PROGRAM :

#include <iostream>

using namespace std;

int main()
{
    int n,i,numbers,sum=0;
    float avg;

    cout << "Enter how many numbers ? :\t" ;
    cin >> n;

    for(i=1;i<=n;i++)
    {
        cout << "\nEnter number " << i <<" :\t";
        cin >> numbers;
        sum=sum+numbers;
    }
    avg= sum/n;
    cout << "\n\nThe average of " << n << " numbers is : \t" << avg << endl;
    return 0;
}
OUTPUT :











Related Programs :

Average of   N numbers in C
Armstrong number in C
Armstrong number in Cpp
Palindrome in Cpp
Palindrome numberin C
Reverse of a number in C