CBSE BOARD XII, asked by devudevutty, 8 months ago

c++ program to create an array of N numbers, find average and display those numbers greater than the average (this is belongs to computer application (commerce)classes)

Answers

Answered by santosh1989sah
3

Answer:

Algorithm to find average of N numbers stored in an array

Let inputArray is an integer array having N elements.

Declare an integer variable 'sum' and initialize it to 0. We will use 'sum' variable to store sum of elements of array.

Using for loop, we will traverse inputArray from array index 0 to N-1.

For any index i (0<= i <= N-1), add the value of element at index i to sum. sum = sum + inputArray[i];

After termination of for loop, sum will contain the sum of all array elements.

Now calculate average = sum/N;

Explanation:

#include <iostream>

using namespace std;

int main() {

int i, count, sum, inputArray[500];

float average;

cout << "Enter number of elements\n";

cin >> count;

cout << "Enter " << count << " elements\n";

// Read "count" elements from user

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;

return 0;

}

Similar questions