+ 1

# Good evening how can find the greatest number between 5 number by using loop?

I need know how can solution?

25th Mar 2017, 3:44 PM
Bts...
+ 1
but he want any 5 number
25th Mar 2017, 4:31 PM
Bts...
0
I don't understand this
25th Mar 2017, 4:26 PM
Bts...
0
int numbers = {1, 3, 5, 7, 2}; int greatest = numbers[0]; for(int counter = 0; counter < 5; counter++) { if(numbers[counter] > greatest) greatest = numbers[counter]; } Also, you can replace the if statement by: greatest = (numbers[counter] > greatest) ? numbers[counter] : greatest;
25th Mar 2017, 4:28 PM
reddylopes
0
#include <iostream> using namespace std; void main() { int counter = 0; int number = 0; int largest = 0; cout << "Please enter up to 10 numbers and I will print the largest one on the screen.\n\n"; while (counter <= 10) { cout << "Number: "; cin >> number; counter++; if (number > largest) { largest = number; } else if (counter == 10) { cout << "The largest number was: " << number; break; } } }
25th Mar 2017, 4:28 PM