Q:

C++ Program to Find Sum and Average of n numbers using for loop

belongs to collection: C++ Number Solved Programs

0

Write a C++ Program to Find Sum and Average of n numbers using for loop. Here’s simple Program to Find Sum and Average of n numbers using for loop in C++ Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Average of n numbers


  • Average of n numbers – The sum of all of the numbers in a list divided by the number of items in that list.
    For example, the mean of the numbers 2, 3, 7 is 4 since 2+3+7 = 12 and 12 divided by 3 [there are three numbers] is 4.

Here is source code of the C++ Program to Find Sum and Average of n numbers using for loop. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.

 
 

SOURCE CODE : :

/*  C++ Program to Find Sum and Average of n numbers using for loop  */

#include<iostream>
using namespace std;

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

    cout<<"How many numbers u want to enter :: ";
    cin>>n;

    for(i=1;i<=n;++i)
    {
        cout<<"\nEnter number "<<i<<" :: ";
        cin>>x;

        sum+=x;
    }

    avg=(float)sum/(float)n;

    cout<<"\n\nSum of "<<n<<" Numbers :: "<<sum;

    cout<<"\n\nAverage of "<<n<<" Numbers :: "<<avg;

    cout<<"\n";

    return 0;
}

Output : : 


/*  C++ Program to Find Sum and Average of n numbers using for loop  */

How many numbers u want to enter :: 6

Enter number 1 :: 1

Enter number 2 :: 2

Enter number 3 :: 3

Enter number 4 :: 4

Enter number 5 :: 5

Enter number 6 :: 6


Sum of 6 Numbers :: 21

Average of 6 Numbers :: 3.5

Process returned 0

Above is the source code for C++ Program to Find Sum and Average of n numbers using for loop which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Number Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ Program to Find Sum of n Natural Numbers using... >>
<< C++ Program to Check Number is Unique Number or No...