- 2
Find the largest number in the user entered array
c++ program
4 Answers
+ 1
#include <iostream>
using namespace std;
int main() {
cout << "Enter 5 numbers" << endl;
int numbers[5];
int maxNum = 0;
for (int x = 0; x < 5; x++) {
cin >> numbers[x];
}
for (int i = 0; i < 5; i++) {
if (maxNum < numbers[i]) {
maxNum = numbers[i];
}
}
cout << "The max number is -> " << maxNum << endl;
return 0;
}
+ 1
@N3tW0rK
Why you run the loop again wouldn't be this better
for (int x = 0; x < 5; x++)
{
cin >> numbers[x];
if (maxNum < numbers[i])
maxNum = numbers[i];
}
+ 1
oh yeah lol :P
0
thnks