Create an array of size 20. Take input from the user and find the highest number from the array.
#include <iostream>
using namespace std;
int main() {
const int N=20;
int i, max, arr[N];
// Store number entered by the user
for(i = 0; i < N; ++i) {
cout << "Enter Number" << i + 1 << ": ";
cin >> arr[i];
}
max = arr[0];
// Loop to find the highest number
for(i = 1; i < N; ++i) {
if(max < arr[i])
max = arr[i];
}
cout << endl << "The highest number from the array = " << max;
return 0;
}
Comments
Leave a comment