Вопрос задан 04.05.2019 в 04:14. Предмет Информатика. Спрашивает Гимаева Лиля.

Составить алгоритм на языке программирования , который выводит среднее арифметическое наибольшего и

наименьшего из 20 элементов , имеющих значение из интервала [-10;10]
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Семиглазов Илья.
Pascal:
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.
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

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.

0 0

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

Последние заданные вопросы в категории Информатика

Задать вопрос