Parzyste nieparzyste elementy tablicy
Jak w opisie. Wartości tabeli są zainicjowane w kodzie programu.
Kompilator: Microsoft Visual Studio
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
int[] Array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int p = 0, np = 0;
foreach (int i in Array1)
if (i % 2 == 0)
{
p++;
}
else
{
np++;
}
Console.Write("parzyste " + p + " nieparzyste " + np);
Console.ReadKey();
Console.Clear();
}
}
}