+ 1

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

I need know how can solution?

5 Answers

+ 1

but he want any 5 number

0

I don't understand this

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;

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;
}
}
}

0

#include <iostream>
using namespace std;
int main(){
int i,n,big= 0;
for (c=1;c <=5;c++){
cout << "Enter a number: ";
cin >>n;
if (n > big){
big= n;
}
}
cout << "The biggest number is " << big;
break;
}