In this article, we will learn about the solution and approach to solve the given problem statement.
Given an array as an input, we need to find the largest element in the array.
Let’s see the implementation below −
def largest(arr,n): #maximal element max = arr for i in range(1, n): if arr[i] > max: max = arr[i] return max # main arr = [10, 24, 45, 90, 98] n = len(arr) Ans = largest(arr,n) print ("Largest in the given array is",Ans)
Largest in the given array is 98
All the variables and functions are declared in global scope as shown in the figure below.
In this article, we learned about the approach to find the largest element in an array.