C++ Program to Find Largest Element in an Array Last Updated : 03 Aug, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will learn to write a C++ program to find the largest element in the given array arr of size N. The element that is greater than all other elements is the largest element in the array. Recommended PracticeHelp a Thief!!!Try It! One of the most simplest and basic approaches to find the greatest element in an array is to simply traverse the whole list and maintain a variable max to store the maximum element so far and compare this max element with the current element and update the max if any element greater than max is encountered. AlgorithmCreate a local variable max to store the maximum among the list.Initialize max with the first element initially, to start the comparison.Then traverse the given array from the second element till the end, and for each element:Compare the current element with the maxIf the current element is greater than max, then replace the value of max with the current element.In the end, return and print the value of the largest element of the array stored in max.C++ Program to Find Largest Number in an Array C++ // C++ program to find maximum // in arr[] of size n #include <bits/stdc++.h> using namespace std; // Function to find the largest // number in array int largest(int arr[], int n) { int i; // Initialize maximum element int max = arr[0]; // Traverse array elements // from second and compare // every element with current max for (i = 1; i < n; i++) if (arr[i] > max) max = arr[i]; return max; } // Driver Code int main() { int arr[] = { 10, 324, 45, 90, 9808 }; int n = sizeof(arr) / sizeof(arr[0]); cout << "Largest in given array is " << largest(arr, n); return 0; } OutputLargest in given array is 9808Complexity AnalysisTime complexity: O(N), to traverse the Array completely.Auxiliary Space: O(1), as only an extra variable is created, which will take O(1) space. Refer to the complete article Program to find largest element in an Array for optimized methods to find the largest element in an array. Comment More infoAdvertise with us Next Article C++ Program to Find Largest Element in an Array kartik Follow Improve Article Tags : Searching Matrix C++ Programs C++ Computer Science Fundamentals DSA Arrays Order-Statistics Arrays +5 More Practice Tags : CPPArraysArraysMatrixSearching +1 More Similar Reads C++ Program to Find the Second Largest Element in an Array In C++, an array is a data structure that is used to store multiple values of similar data types in a contiguous memory location. In this article, we will learn how to find the second largest element in an array in C++. Examples: Input: arr[] = {34, 5, 16, 14, 56, 7, 56} Output: 34 Explanation: The 3 min read C++ Program to Find the K'th largest element in a stream Given an infinite stream of integers, find the k'th largest element at any point of time.Example: Input:stream[] = {10, 20, 11, 70, 50, 40, 100, 5, ...}k = 3Output: {_, _, 10, 11, 20, 40, 50, 50, ...} Extra space allowed is O(k). Recommended: Please solve it on "PRACTICE" first, before moving on to 7 min read Program to find largest element in an array using Dynamic Memory Allocation Given an array arr[] consisting of N integers, the task is to find the largest element in the given array using Dynamic Memory Allocation. Examples: Input: arr[] = {4, 5, 6, 7} Output: 7Explanation:The largest element present in the given array is 7. Input: arr[] = {8, 9, 10, 12} Output: 12Explanati 5 min read C++ Program for Third largest element in an array of distinct elements Given an array of n integers, find the third largest element. All the elements in the array are distinct integers. Example :  Input: arr[] = {1, 14, 2, 16, 10, 20} Output: The third Largest element is 14 Explanation: Largest element is 20, second largest element is 16 and third largest element is 1 5 min read C++ Program to Find the Minimum and Maximum Element of an Array Given an array, write functions to find the minimum and maximum elements in it. Example: C++ // C++ program to find minimum (or maximum) element // in an array. #include <bits/stdc++.h> using namespace std; int getMin(int arr[], int n) { int res = arr[0]; for (int i = 1; i < n; i++) res = 3 min read Like