0

What program should do?

Write a program that read 5 decimal numbers and store these numbers in an array. Identify the suitable name, type and size of this array. You program should be able to display the contents of this array together with sum and average of all elements of the array

20th Jan 2021, 1:22 PM
Izzat Idham
Izzat Idham - avatar
2 ответов
+ 2
Your code is woRkiNg properly according to your mentioned input output i did little changes try it #include <iostream> using namespace std; int main() { int n, i; float num[100], sum=0.0, average; cout << "Enter the numbers of data:\n "; cin >> n; while (n > 100 || n <= 0) { cout << "Error! number should in range of (1 to 100)." << endl; cout << "\nEnter the number again: "; cin >> n; } for(i = 0; i < n; ++i) { cout << i + 1 << "\n Enter number:\n "; cin >> num[i]; sum += num[i]; } average = sum / n; cout<<sum<<endl; cout << "\nAverage = " << average; return 0; }
20th Jan 2021, 2:53 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
20th Jan 2021, 2:13 PM
Izzat Idham
Izzat Idham - avatar