
Составить программу для решения задачи : "Заполнить массив из 20 элементов случайным образом из
диапазонов [20;90] и найти их сумму"

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

Ответ: python
import random
a = [0]*20
s = 0
for i in range(len(a)):
a[i] = random.randint(20,90)
s += a[i]
print(a)
print(s)



Program to Fill an Array with Random Numbers and Find their Sum
Here is a program written in Python that fills an array with 20 random numbers within the range of 20 to 90 and calculates their sum:
```python import random
# Create an empty array array = []
# Fill the array with 20 random numbers for _ in range(20): number = random.randint(20, 90) array.append(number)
# Calculate the sum of the numbers in the array sum_of_numbers = sum(array)
# Print the array and the sum print("Array:", array) print("Sum:", sum_of_numbers) ```
This program uses the `random` module in Python to generate random numbers within the specified range. The `randint()` function is used to generate random integers between 20 and 90, and these numbers are appended to the array. Finally, the `sum()` function is used to calculate the sum of the numbers in the array, and the result is printed.
Please note that this program is written in Python. If you are using a different programming language, the syntax and functions may vary.
I hope this helps! Let me know if you have any further questions.


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