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)
Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.