Вопрос задан 30.10.2023 в 12:07. Предмет Информатика. Спрашивает Филатов Ваня.

Составить программу, которая вычисляет сумму и среднее арифметическое положительных чисел.

0 0
Перейти к ответам

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

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

Для начала каких чисел?

Они вводятся или нет?

Ох, ладно

Допустим, вводятся)

Python

Я ввожу число и все положительные числа, которые входят в него будут проходить через программу...

n = int(input())

g = 0

l = 0

for i in range(n+1):

   g += 1

   l += i

g -= 1

print( l // g )

Пример

Ввод: 5

Вывод: 3

Как получилось:

1+2+3+4+5=15

кол-во цифр = 5

15 / 5 =3

Как-то так

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.
#### Program to Calculate the Sum and Average of Positive Numbers Here is a program written in C++ that calculates the sum and average of positive numbers: ```cpp #include int main() { int n; std::cout << "Enter the number of elements: "; std::cin >> n; int sum = 0; int count = 0; for (int i = 0; i < n; i++) { int num; std::cout << "Enter number " << i + 1 << ": "; std::cin >> num; if (num > 0) { sum += num; count++; } } double average = static_cast(sum) / count; std::cout << "Sum of positive numbers: " << sum << std::endl; std::cout << "Average of positive numbers: " << average << std::endl; return 0; } ``` This program prompts the user to enter the number of elements and then asks for each number one by one. It checks if the number is positive and adds it to the sum if it is. It also keeps track of the count of positive numbers. Finally, it calculates the average by dividing the sum by the count and displays the sum and average of the positive numbers. Please note that this program assumes the user will enter valid integer inputs. If the user enters non-integer values, the program may produce unexpected results. Let me know if you have any further questions!
0 0

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

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

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

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