Вопрос задан 28.04.2019 в 02:51. Предмет Информатика. Спрашивает Кубіцька Віка.

40 элементов массива найти сумму отрицательных элементов кратных 5

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

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Бакирова Назгуль.
Var a:array[1..40] of integer;
i,s:integer;
begin
s:=0;
for i:=1 to 40 do begin
a[i]:=random(200)-100;
Writeln('a[',i,']=',a[i]);
if (a[i] mod 5=0) and (a[i]<0) then
s:=s+a[i];
end;
Writeln('Сумма отрицательных элементов кратных 5 равна: ',s);
end.
0 0
Отвечает Супруненко Аня.
For i:=1 to 40 do begin   
if (a[i]<0) and (a[i] mod 5 =0) then k:=k+a[i];   
end;   
writeln;   
write('сумма ',k);
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Finding the Sum of Negative Elements in an Array that are Multiples of 5

To find the sum of negative elements in an array that are multiples of 5, you can follow these steps:

1. Create an Array: First, create an array with 40 elements. This array will contain both positive and negative numbers.

2. Iterate Through the Array: Next, iterate through the array and identify the negative elements that are multiples of 5.

3. Calculate the Sum: Finally, calculate the sum of these identified negative elements that are multiples of 5.

Here's a simple example of how you might achieve this in JavaScript:

```javascript // Create an array with 40 elements let array = [5, -10, 15, -20, 25, -30, 35, -40, 45, -50, 55, -60, 65, -70, 75, -80, 85, -90, 95, -100, 105, -110, 115, -120, 125, -130, 135, -140, 145, -150, 155, -160, 165, -170, 175, -180, 185, -190, 195, -200];

// Calculate the sum of negative elements that are multiples of 5 let sum = 0; for (let i = 0; i < array.length; i++) { if (array[i] < 0 && array[i] % 5 === 0) { sum += array[i]; } }

console.log("The sum of negative elements in the array that are multiples of 5 is: " + sum); ```

This code creates an array with 40 elements and then calculates the sum of the negative elements that are multiples of 5.

Please note that the specific implementation may vary based on the programming language you are using.

0 0

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

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

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