C# Program to find even and odd elements in an array


In this program, You will learn how to find even and odd elements in an array in C#.


int[] arr = new int[5];

Example: How to find even and odd elements in an array in C#.

using System;
public class Program
{
	public static void Main(string[] args)
	{
		int i;
		int[] arr = new int[5];

		Console.Write("Enter five numbers:");
		for (i = 0; i < arr.Length; i++)
		{
			arr[i] = Convert.ToInt32(Console.ReadLine());
		}

		Console.Write("Even list is:");
        for (i = 0; i < 5; i++)
        {
            if (arr[i] % 2 == 0)
            {
				Console.Write(" " + arr[i]);
            }
        }

		Console.Write("\nOdd List is:");
        for (i = 0; i < 5; i++)
        {
            if (arr[i] % 2 != 0)
            {
				Console.Write(" " + arr[i]);
            }
        }
	}
}

Output:

Enter five numbers:10
11
12
13
14
Even list is: 10 12 14
Odd List is: 11 13