In C#, please.
Create a program that will accept inputs into 5x5 25-element two-dimensional
integer array Count2D5x5Array. 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.Globalization;
namespace App
{
class Program
{
static void Main(string[] args)
{
int[,] Count2D5x5Array = new int[5, 5];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
Console.Write("Enter the value [{0},{1}]: ", i, j);
Count2D5x5Array[i, j] = int.Parse(Console.ReadLine());
}
}
int oddNumbers=0;
int evenNumbers=0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if(Count2D5x5Array[i, j]%2==0){
evenNumbers++;
}else{
oddNumbers++;
}
}
}
Console.WriteLine("The odd numbers that appeared in the list: {0}", oddNumbers);
Console.WriteLine("The even numbers that appeared in the list: {0}", evenNumbers);
Console.ReadLine();
}
}
}
Comments
Leave a comment