You are here: Home / Topics / Python program to find maximum in arr[] of size n

Python program to find maximum in arr[] of size n

Filed under: Python on 2023-09-17 22:24:05

#!/usr/bin/python
# -*- coding: utf-8 -*-

# 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


arr = [10, 324, 45, 90, 9808]
n = len(arr)
Ans = largest(arr, n)
print ('Largest in given array is', Ans)

About Author:
S
Shyam Dubey     View Profile
If you are good in any field. Just share your knowledge with others.