C# Program to check number is even or odd


In this program, You will learn how to check number is even or odd in C#.


if(num % 2 == 0) { 
    //statement
}

Example: How to check number is even or odd in C#.

using System;
public class Test
{
	public static void Main(string[] args)
	{
		int n;
		Console.Write("Enter a number:");
		n = Convert.ToInt32(Console.ReadLine());

		if (n % 2 == 0)
		{
			Console.WriteLine("Number is even:" + n);
		}
		else
		{
			Console.WriteLine("Number is odd:" + n);
		}

	}
}

Output:

Enter a number:14
Number is even:14