
Составить алгоритм на языке программирования , который выводит среднее арифметическое наибольшего и
наименьшего из 20 элементов , имеющих значение из интервала [-10;10]

Ответы на вопрос

const n=20;
var a: array[1..n] of integer;
max, min, i: integer;
begin
max:=-11;
min:=11;
for i:=1 to n do begin
a[i]:=random(20)-10; {или readln(a[i]); если нужен конкретный ввод}
if a[i]>max then max:=a[i];
if a[i]<min then min:=a[i];
end;
writeln((max+min)/2);
end.



Algorithm for Finding the Average of the Largest and Smallest of 20 Elements
To create an algorithm in Python that calculates the average of the largest and smallest of 20 elements within the range [-10, 10], you can follow these steps:
1. Generate 20 Random Numbers within the Specified Range: - Use a random number generator to create a list of 20 elements with values in the range [-10, 10].
2. Find the Largest and Smallest Numbers: - Iterate through the list to find the largest and smallest numbers.
3. Calculate the Average: - Add the largest and smallest numbers together and divide the sum by 2 to find the average.
Here's a Python algorithm to achieve this:
```python import random
# Step 1: Generate 20 Random Numbers within the Specified Range random_numbers = [random.randint(-10, 10) for _ in range(20)]
# Step 2: Find the Largest and Smallest Numbers largest = max(random_numbers) smallest = min(random_numbers)
# Step 3: Calculate the Average average = (largest + smallest) / 2
print("Random Numbers:", random_numbers) print("Largest Number:", largest) print("Smallest Number:", smallest) print("Average of Largest and Smallest:", average) ```
This algorithm uses Python's built-in functions to find the largest and smallest numbers and then calculates their average.
Please note that the algorithm provided is in Python, as it is a widely used and easy-to-understand language for such tasks. If you have a specific programming language in mind, I can tailor the algorithm accordingly.


Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili