top of page

Find the Largest Element

  • Shreyas Naphad
  • May 8, 2024
  • 1 min read

Updated: Jun 6, 2024

In this article, we aim to solve the problem of finding the largest element from an array. So this simply means that we have been given an array and our task is to find the largest number present in the array.

Problem Statement:

Given an array of integers, write a program to find the largest element present in the array.

Example:

Arr = [20,4,0,11,35,6,7]

Output: 35

The C++ Code to solve this problem is as follows:

Solution:

 

Code Explanation:

·        Initially we consider the first number of the array as the largest.

·        We then traverse the array and check if any element is greater than the largest and if such an element is present then we update our largest.

·        Finally, the variable largest will have the largest element of the array.

 

Time Complexity: O(N)

Space Complexity: O(1)

Comments


©2025 by DevSparks.

bottom of page