C++ Program to Find Largest Element of an Array

In the previous article, we have discussed C++ Program to Calculate Grade of Student Using Switch Case. In this article, we will see C++ Program to Find Largest Element of an Array.

C++ Program to Find Largest Element of an Array

  • How to find maximum element of an array in C++.

C++ Program to find maximum element of an array

C++ Program to find maximum element of an array

#include <iostream>
 
using namespace std;
   
int main(){
    int inputArray[500], N, i, max;
       
    cout << "Enter Number of Elements in Array\n";
    cin >> N;
    cout << "Enter " << N << " numbers\n";
      
    /* Read array elements */
    for(i = 0; i < N; i++){
        cin >> inputArray[i];
    }
      
    max = inputArray[0];
    /* traverse array elements */
    for(i = 1; i < N; i++){
        if(inputArray[i] > max)
            max = inputArray[i];
    }
      
    cout << "Maximum Element : " << max;
           
    return 0;
}

Output

Enter Number of Elements in Array
7
Enter 7 numbers
2 7 1 5 3 10 8
Maximum Element : 10

Discover a comprehensive collection of C++ Program Examples ranging from easy to complex ones and get help during your coding journey.