How to find the largest number in an array in Python 3
Example Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# Python3 program to find maximum # in arr[] of size n # python function to find maximum # in arr[] of size n def largest(arr,n): # Initialize maximum element max = arr[0] # Traverse array elements from second # and compare every element with # current max for i in range(1, n): if arr[i] > max: max = arr[i] return max # Driver Code arr = [10,20,5,3,7] n = len(arr) Ans = largest(arr,n) print ("Largest in given array is",Ans) |
Output: