Write a C++ program that asks the user to enter 10 integer values in an array. After entering 10
elements find the maximum number and display it on output screen.
#include <iostream>
using namespace std;
int main() {
int i, max, arr[10];
// Store number entered by the user
for(i = 0; i < 10; ++i) {
cout << "Enter Number_" << i + 1 << " : ";
cin >> arr[i];
}
max = arr[0];
// Loop to find the maximum number
for(i = 1; i < 10; ++i) {
if(max < arr[i])
max = arr[i];
}
cout << endl << "Largest element = " << max;
return 0;
}
Comments
Leave a comment