Написать программу, находящую максимальный элемент массива

31 Дек 2019 в 19:44
176 +1
0
Ответы
1

Sure! Here is an example program in Python that finds the maximum element in an array:

def find_max_element(arr):
max_element = arr[0]
for i in range(1, len(arr)):
if arr[i] > max_element:
max_element = arr[i]
return max_element
# Test the function
array = [3, 7, 2, 10, 5]
max_element = find_max_element(array)
print("The maximum element in the array is:", max_element)

This program defines a function called find_max_element that takes an array as input and returns the maximum element in the array. It then tests the function by creating an array [3, 7, 2, 10, 5] and prints out the maximum element in the array.

18 Апр 2024 в 22:15
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Гарантированные бесплатные доработки в течение 1 года
Быстрое выполнение от 2 часов
Проверка работы на плагиат
Поможем написать учебную работу
Прямой эфир