Python Program to find maximum element in an array

Program

number_array = list()
size = int(input("Enter the size of array:\t"))
print("Enter the numbers in array: ")
for i in range(int(size)):
    n = input()
    number_array.append(int(n))
max = number_array[0]
location = int(0)
index = int(1)
for index in range(len(number_array)):
    if number_array[index] > max:
        max = number_array[index]
        location = index
print("Maximum element in the array is: ", max)
print("Position is ", location + 1)

Output

$ python3 maximum_element_in_array.py
Enter the size of array:        5
Enter the numbers in array:
234
899
45
345
678
Maximum element in the array is:  899
Position is  2

Tags: