Phone

+919997782184

Email

support@roboticswithpython.com

Geeks of Coding

Join us on Telegram

Home Forums Cody Bank Python Program to find largest element in an array

Viewing 0 reply threads
  • Author
    Posts
    • #1068
      Abhishek TyagiAbhishek Tyagi
      Keymaster

      Given an array, find the largest element in it.

      Input : arr[] = {5, 200, 3}
      Output : 200

      Input : arr[] = {22, 56, 10, 2, 60}
      Output : 60

      # 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
        
      # Example Driver Code 
      arr = [10, 324, 45, 90, 9808] 
      n = len(arr) 
      Ans = largest(arr,n) 
      print ("Largest in given array is",Ans)
Viewing 0 reply threads
  • You must be logged in to reply to this topic.