C++ Program to Find Largest Element of an Array

Here is a C++ program to find the 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

Recommended Posts
C++ Program to Find Smallest Element in Array
C++ Program to Print Array in Reverse Order
C++ Program to Delete Vowels Characters from String
C++ Program to Access Elements of an Array Using Pointer
C++ Program to Find the Frequency of Characters in a String
C++ Program to Count Number of Vowels, Consonant, and Spaces in String
C++ Program to Find Average of Numbers Using Arrays
C++ Program to Calculate Average Percentage Marks
C++ Program to Multiply Two Numbers Using Addition
All C++ Programs