Вопрос задан 18.06.2023 в 05:21. Предмет Информатика. Спрашивает Мозжерина Алина.

Срочно! Написать программу. В массиве из 8 элементов найти сумму и количество чисел, кратных 9 и

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

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

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

Python

my_list = [int(input()) for i in range(8)]

res = [i for i in my_list if i % 9 == 0 and i % 8 == 0]

print(f'Кол-во чисел: {len(res)}')

print(f'Сумма чисел: {sum(res)}')

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

Program to Find the Sum and Count of Numbers Divisible by 9 and 8 in an Array

To write a program that finds the sum and count of numbers divisible by 9 and 8 in an array, you can follow these steps:

1. Initialize an array with 8 elements. 2. Prompt the user to enter 8 numbers and store them in the array. 3. Initialize variables to keep track of the sum and count of numbers divisible by 9 and 8. 4. Iterate over each element in the array. 5. Check if the current element is divisible by both 9 and 8. 6. If it is divisible, increment the count and add the element to the sum. 7. After the loop, print the sum and count of numbers divisible by 9 and 8.

Here's an example implementation in Python:

```python # Step 1: Initialize an array with 8 elements array = [0] * 8

# Step 2: Prompt the user to enter 8 numbers and store them in the array for i in range(8): array[i] = int(input(f"Enter number {i+1}: "))

# Step 3: Initialize variables to keep track of the sum and count sum_divisible = 0 count_divisible = 0

# Step 4: Iterate over each element in the array for num in array: # Step 5: Check if the current element is divisible by both 9 and 8 if num % 9 == 0 and num % 8 == 0: # Step 6: If it is divisible, increment the count and add the element to the sum count_divisible += 1 sum_divisible += num

# Step 7: Print the sum and count of numbers divisible by 9 and 8 print(f"The sum of numbers divisible by 9 and 8 is: {sum_divisible}") print(f"The count of numbers divisible by 9 and 8 is: {count_divisible}") ```

Please note that this program assumes the user will enter valid integer values for the array elements. If you want to add error handling for invalid inputs, you can modify the code accordingly.

I hope this helps! Let me know if you have any further questions.

0 0

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

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

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

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