Average of Numbers

Description:

Your Task is to read some numbers from the user and print their average value (use arrays). Input : first line is the number of numbers user will enter (N) then, there are N-numbers as input Output : The Average value of these numbers Sample Input : Enter how many numbers and the numbers: 3 1 5 6 Sample Output : 4 Sample Input : Enter how many numbers and the numbers: 2 17 19 Sample Output : 18 Test Case 1 Input (stdin) 3 1 5 6 Expected Output 4 Test Case 2 Input (stdin) 5 1 2 3 4 5 Expected Output 3

Program :

#include <iostream>

using namespace std;

int main()

{

    int n, i;

    float num[100], sum=0.0, average;

    //cout << "Enter the numbers of data: ";

    cin >> n;

    while (n > 100 || n <= 0)

    {

        cout << "Error! number should in range of (1 to 100)." << endl;

        //cout << "Enter the number again: ";

        cin >> n;

    }

    for(i = 0; i < n; ++i)

    {

        //cout << i + 1 << ". Enter number: ";

        cin >> num[i];

        sum += num[i];

    }

    average = sum / n;

    cout << average;

    return 0;

}