Вопрос задан 18.06.2023 в 14:15. Предмет Информатика. Спрашивает Костин Егор.

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

диапазонов [20;90] и найти их сумму"
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Афансьев Павел.

Ответ: 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)

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

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.

0 0

Похожие вопросы

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

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

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