Using an array write a program that asks for 10 numbers of type int stores it in an array and traversing each item counting the number of items that are greater than 5. Display the result.
Code
#include <iostream>
using namespace std;
int main() {
int numbers[10];
// Input
cout << "Enter ten integernumbers: ";
for (int i = 0; i < 10; i++) {
cin >> numbers[i];
}
// Output
int counter = 0;
for (int i = 0; i < 10; i++) {
if (numbers[i] > 5) {
counter++;
}
}
cout << "There is " << counter << " greater than5.";
return 0;
}
Result
Enter ten integer numbers: 1 2 3 11 7 8 12 15 6 3
There is 6 greater than 5.