Skip to content

Commit 1a5dd9d

Browse files
committed
Write a Python Program to find largest element in an array.
1 parent 2936360 commit 1a5dd9d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def find_largest_element(arr):
2+
if not arr:
3+
return "Array is empty"
4+
# Initialize the first element as the largest
5+
largest_element = arr[0]
6+
# Iterate through the array to find the largest element
7+
for element in arr:
8+
if element > largest_element:
9+
largest_element = element
10+
return largest_element
11+
# Example usage:
12+
my_array = [10, 20, 30, 99]
13+
result = find_largest_element(my_array)
14+
print(f"The largest element in the array is: {result}")
15+
# The largest element in the array is: 99

0 commit comments

Comments
 (0)