Python-100-Days/Day01-15/code/Day05/largest.py

20 lines
390 B
Python

``` Given an array, find the largest element in it.
Input : arr[] = {10, 20, 4}
Output : 20
Input : arr[] = {20, 10, 20, 4, 100}
Output : 100 ```
def largest(arr,n):
max = arr[0]
for i in range(1, n):
if arr[i] > max:
max = arr[i]
return max
arr = [10, 324, 45, 90, 9808]
n = len(arr)
Ans = largest(arr,n)
print ("Largest in given array is",Ans)