Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Program to Calculate Average of Multiple Numbers Using Arrays in CPP (C plus plus)

Program to Calculate Average of Multiple Numbers Using Arrays in CPP (C plus plus)

In this tutorial, we will learn about the Program to Calculate Average of Multiple Numbers Using Arrays in CPP (C plus plus).

#include <iostream>

using namespace std;

int main()
{
	float avg;
    int no;
	int k;
	float add=0.0;
    float num[100];
	
	
    cout<<"Please enter the no. of data: ";
    cin>>no;

    while(no>100||no<=0)
    {
        cout<<"Error!"<<"Entered number should be in range of [1-100]."<<endl<<endl;
        
        cout<<"Please enter the number again: ";
        cin>>no;
    }

    for(k=0;k<no;++k)
    {
        cout<<k+1<<". Please enter number: ";
        cin>>num[k];
        
        add+=num[k];
    }

    avg=add/no;
    cout<<"Average = "<<avg;

    return 0;
}

Output:

Program to Calculate Average of Multiple Numbers Using Arrays in CPP (C plus plus)

Program to Calculate Average of Multiple Numbers Using Arrays in CPP (C plus plus)