C++ Program to Calculate 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

Leave a Comment