Skip to content

Commit d3b2130

Browse files
Abhisharma85techyminati
authored andcommitted
Added Program to find largest element in an array
1 parent ba0f02c commit d3b2130

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎largest_element_array.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Python program to find maximum
2+
# in arr[] of size n
3+
4+
# python function to find maximum
5+
# in arr[] of size n
6+
7+
8+
def largest(arr, n):
9+
10+
# Initialize maximum element
11+
max = arr[0]
12+
13+
# Traverse array elements from second
14+
# and compare every element with
15+
# current max
16+
for i in range(1, n):
17+
if arr[i] > max:
18+
max = arr[i]
19+
return max
20+
21+
22+
# Driver Code
23+
arr = [10, 324, 45, 90, 9808]
24+
n = len(arr)
25+
Ans = largest(arr, n)
26+
print("Largest in given array ", Ans)
27+
28+

0 commit comments

Comments
 (0)