- 2

Find the largest number in the user entered array

c++ program

20th Jan 2017, 4:50 AM
sameer
sameer - avatar
4 Respuestas
+ 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; }
20th Jan 2017, 5:15 AM
Kawaii
Kawaii - avatar
+ 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]; }
20th Jan 2017, 5:45 AM
Megatron
Megatron - avatar
+ 1
oh yeah lol :P
20th Jan 2017, 5:56 AM
Kawaii
Kawaii - avatar
0
thnks
20th Jan 2017, 11:22 AM
sameer
sameer - avatar