Find Average of Numbers Using Arrays Program in C++

Google Advertisements

Prev Tutorial Next Tutorial

C++ Program to Find Average of Numbers Using Arrays

Average of numbers is calculated by adding all the numbers and then dividing the sum by count of numbers available.
In below code we receive integer input from user and storing it in array. Then we will find the sum of all array elements using for loop and finally calculate the average of N input numbers stored in an array.

To understand this code you need basic knowledge about Array in C++ and For Loop in C++.

Example

The numbers whose average is to be calculated are:
10, 20, 30, 40, 50
Sum of numbers = 150
Average of numbers = 150/5 = 30

C++ Program to Find Average of Numbers Using Arrays

#include<iostream.h>
#include<conio.h>

void main()
{
int i, count, sum, inputArray[500];
float average;
clrscr();

cout<<"Enter number of Elements: ";
cin >> count;

cout<<"Enter " << count << " any Elements in Array:\n";
for(i = 0; i < count; i++) {
cin >> inputArray[i];
}

sum = 0;
// Find sum of all array elements
for(i = 0; i < count; i++) {
sum += inputArray[i];
}

average = (float)sum / count;
cout << "Average: " << average;

getch();
}

Output

Enter number of Elements: 5
Enter any Elements in Array: 
20
40
30
50
10
Average: 30
search array element program in c++
Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. For Advertisement contact on [email protected] or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: [email protected] or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar. Difference between path and classpath in Java

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: [email protected] or 8076671483 Try this Keyword C++ Programs