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:
M
Mr. Dubey     View Profile
Founder of MCQ Buddy. I just like to help others. This portal helps students in getting study material free. Share your stuff here so that others can get benefitted.