Average Program Using C++ Programming Language

Average: The result or amount obtained by adding several amounts divided by the total no.of numbers.

average =  sum of numbers / total no.of numbers

Let n1 , n2 , n3 , n4 , ..... are the numbers and total number of numbers are " n "

average = n1 + n2 + n3 + n3 + n4 +  .......   / n

Example Find the average of following numbers ?
 2 , 2 
Solution:
average  = 2 + 2 / 2 = 2

Recommended Articles:

Program code:

#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
cout<<endl;
cout<<"*************************************************"<<endl;
cout<<"                Average of Numbers               "<<endl;
cout<<"*************************************************"<<endl<<endl;
int n;
double num , ans  ,  snum = 0; 
char redo;
do
{
     cout<<"Enter Total numbers value   n  =  ";
     cin>>n;
     cout<<endl<<endl;
     cout<<"Enter Values one by one and press enter "<<endl<<endl;
     for(int i = 0 ; i < n ; i++)
    {
    cin>>num;
    cout<<endl;
    snum = snum + num ;
        }
            ans =  snum / n ;
            cout<<"Average of Numbers you entered is   =   "<<ans;
            cout<<endl<<endl;
    
            cout<<"*************************************************"<<endl;
            
            cout<<"For more Calculation enter y or Y  =   ";
            cin>>redo;
            cout<<endl<<endl;
            
    }while(redo  == 'y' ||  redo == 'Y');
    
   getch();
}


Output: After compile and run , the output will be

Click on Pic to Enlarge it.

Hope that you will find this helpful.



No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.