Вопрос задан 15.06.2023 в 00:48. Предмет Информатика. Спрашивает Миронова Полина.

Домашнее задание Дана последовательность, состоящая из N чисел. Найдите сум- му членов этой

последовательности, которые делятся на к без остатка (1<=K, N<100).
0 0
Перейти к ответам

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

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

Ответ:

k=int(input('K: '))

n=int(input('N: '))

s=0

for i in range(n):

   c=int(input('Введите число: '))

   if c%k==0:

       s+=1

print('Сумма чисел, делящихся на k без остатка:',s)

0 0
Отвечает Аксёнова Ольга.

var k, n, a, i, s: integer;

begin

   readln(k, n);

   s := 0;

   for i:=1 to n do begin read(a); if (a mod k) = 0 then s += a; end;

   write(s);

end.

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

Finding the Sum of Numbers Divisible by K in a Sequence

To find the sum of numbers in a sequence that are divisible by a given number K, you can follow these steps:

1. Initialize a variable `sum` to 0. This variable will keep track of the sum of the numbers divisible by K. 2. Iterate through each number in the sequence. 3. For each number, check if it is divisible by K without any remainder. 4. If the number is divisible by K, add it to the `sum` variable. 5. Repeat steps 3 and 4 for all numbers in the sequence. 6. After iterating through all the numbers, the final value of `sum` will be the sum of the numbers divisible by K in the sequence.

Please note that the given sequence consists of N numbers, and the value of K should be greater than or equal to 1 and less than or equal to 100.

Let's consider an example to illustrate this process:

Suppose we have the sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and we want to find the sum of the numbers divisible by 3.

- Initialize `sum` to 0. - Iterate through each number in the sequence: - For the first number, 1, it is not divisible by 3, so we skip it. - For the second number, 2, it is not divisible by 3, so we skip it. - For the third number, 3, it is divisible by 3, so we add it to `sum`. The updated value of `sum` is now 3. - For the fourth number, 4, it is not divisible by 3, so we skip it. - For the fifth number, 5, it is not divisible by 3, so we skip it. - For the sixth number, 6, it is divisible by 3, so we add it to `sum`. The updated value of `sum` is now 9. - For the seventh number, 7, it is not divisible by 3, so we skip it. - For the eighth number, 8, it is not divisible by 3, so we skip it. - For the ninth number, 9, it is divisible by 3, so we add it to `sum`. The updated value of `sum` is now 18. - For the tenth number, 10, it is not divisible by 3, so we skip it. - After iterating through all the numbers, the final value of `sum` is 18, which is the sum of the numbers divisible by 3 in the sequence [1, 2, 3, 4, 5,

0 0

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

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

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

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