Create a program that will accept inputs into a 20-element one-dimensional integer
array CountArray. Your program should count the odd and even numbers that appeared in
the list of accepted values.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
/*
* Create a program that will accept inputs into a 20-element one-dimensional integer
array CountArray. Your program should count the odd and even numbers that appeared in
the list of accepted values.
*/
int[] CountArray = new int[20];
int oddCount = 0;
int evenCount = 0;
for (int i = 0; i < CountArray.Length; i++)
{
Console.WriteLine("Input [{0}] number :", i + 1);
CountArray[i] = Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < CountArray.Length; i++)
{
if (CountArray[i] % 2 == 0)
evenCount++;
if (CountArray[i] % 2 != 0)
oddCount++;
}
Console.WriteLine("Odd count: {0}", oddCount);
Console.WriteLine("Even count: {0}", evenCount);
Console.ReadKey();
}
}
}
Comments
Leave a comment