Answer to Question #47672 in C++ for

Question #47672
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.
1
Expert's answer
2014-10-08T10:39:38-0400
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.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS