Получить удвоенную сумму положительных членов последовательности - C#
Формулировка задачи:
int[] mas = new int[100];
int i = 0;
string q;
int count = 0;
Console.Write("Введите значения массива, после ввода каждого из значений нажмите кнопку Return:");
do
{
q = Console.ReadLine();
if (q == "555") break;
mas[i] = Convert.ToInt32(q);
i++; count++;
}
while (true);
Console.Write("Вывод: ");
{
for (int j = 0; j < count; j++)
{
if (mas[j] >= 0)
{
Console.Write("Что писать здесь???");
}
else
{
continue;
}
}
}
Console.ReadLine();Решение задачи: «Получить удвоенную сумму положительных членов последовательности»
textual
Листинг программы
using System;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
double sum = 0;
Console.WriteLine("Введите размерность массива");
int n = int.Parse(Console.ReadLine());
int[] massiv = new int[n];
Console.WriteLine("Заполните массив");
for (int i = 0; i < massiv.Length; i++)
{
Console.Write("Введите элемент [{0}] ",i);
massiv[i] = int.Parse(Console.ReadLine());
}
for (int i =0; i < massiv.Length; i++)
{
if (massiv[i] > 0)
{
sum += massiv[i];
}
}
Console.WriteLine("Удвоенная сумма положительных элементов: {0}",sum*2);
Console.ReadKey();
}
}
}