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

Ввести одномерный массив А из 13 элементов . Определить в нём сумму модулей отрицательных элементов.

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

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

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

Ответ:

PascalABC.NET

begin

 var A := ReadArrInteger('введите массив с клавиатуры: ', 13);

 A.Where(x-> x < 0).Select(x -> abs(x)).Sum.Println;

end.

0 0
Отвечает Мартынов Данил.

using System;

namespace ConsoleApp1

{

   class Program

   {

       static void Main(string[] args)

       {

           int n = 13;

           int[] array = new int[n];

           int result = 0;

           for (int i = 0; i < n; i++)

           {

               array[i] = int.Parse(Console.ReadLine());

               if (array[i] < 0)

                   result += Math.Abs(array[i]);

           }

           Console.WriteLine("Cумма модулей отрицательных элементов равна {0}", result);

           Console.ReadKey();

       }

   }

}

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

Sure! Here's an example of how you can solve this problem using Python:

python
A = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13] sum_of_negative_mods = 0 for num in A: if num < 0: sum_of_negative_mods += abs(num) print("Sum of the absolute values of negative elements:", sum_of_negative_mods)

In this code, we initialize the array A with 13 elements. Then, we iterate through each element in the array. If the element is negative (less than 0), we add its absolute value (abs(num)) to the sum_of_negative_mods variable. Finally, we print the sum of the absolute values of the negative elements.

In the given example, the output will be:

mathematica
Sum of the absolute values of negative elements: 56

Please note that this code assumes the array A is already defined and contains 13 elements. You can modify the values in the array as per your requirements.

0 0

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

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

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

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