
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program to find largest element in an array
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement
Given an array as an input, we need to find the largest element in the array.
Approach
- We initialize max as the first element.
- After this, we traverse the given array from the second element till end.
- For every traversed element, we compare it with the current value of max
- if it is greater than max, then max gets updated.
- Otherwise, the statement surpasses
Let’s see the implementation below −
Example
def largest(arr,n): #maximal element max = arr[0] for i in range(1, n): if arr[i] > max: max = arr[i] return max # main arr = [10, 24, 45, 90, 98] n = len(arr) Ans = largest(arr,n) print ("Largest in the given array is",Ans)
Output
Largest in the given array is 98
All the variables and functions are declared in global scope as shown in the figure below.
Conclusion
In this article, we learned about the approach to find the largest element in an array.
- Related Articles
- Python Program to find the largest element in an array
- Program to find largest element in an array in C++
- C++ Program to Find Largest Element of an Array
- Golang Program to Find the Largest Element in an Array
- C# Program to find the largest element from an array
- Kth Largest Element in an Array in Python
- Program to find out the index in an array where the largest element is situated in Python
- C# Program to find the largest element from an array using Lambda Expressions
- Python Program to find the largest element in a tuple
- Kth Largest Element in an Array
- Java program to find Largest, Smallest, Second Largest, Second Smallest in an array
- C++ Program to find the second largest element from the array
- Java program to find the largest number in an array
- Program to find maximum XOR with an element from array in Python
- Python Program to Find the Largest Element in a Doubly Linked List

Advertisements