Найти сумму номеров тех элементов последовательности, которые отрицательны. Нумерацию элементов начать с единицы. Нужен код программы. На языке C# (c sharp)
class Program { static void Main() { int[] numbers = {5, -3, 8, -2, 0, -6, 4};
int sumOfNegativeIndices = 0; for (int i = 0; i < numbers.Length; i++) { if (numbers[i] < 0) { sumOfNegativeIndices += i + 1; // учитываем нумерацию, начиная с 1 } } Console.WriteLine("Сумма номеров отрицательных элементов: " + sumOfNegativeIndices); }
using System;
class Program
int sumOfNegativeIndices = 0;{
static void Main()
{
int[] numbers = {5, -3, 8, -2, 0, -6, 4};
for (int i = 0; i < numbers.Length; i++)
{
if (numbers[i] < 0)
{
sumOfNegativeIndices += i + 1; // учитываем нумерацию, начиная с 1
}
}
Console.WriteLine("Сумма номеров отрицательных элементов: " + sumOfNegativeIndices);
}
}