Odd Even Program in C#

Prev Tutorial Next Tutorial

Odd Even Number Program in C#

Even number is divisible by 2 but Odd number is not divisible by 2. Here we apply this concept to write even odd program in C#. To display any message on screen we use WriteLine() the static method of Console class.

Check Number is Odd or Even Program in C#

using System;  
public class Odd_Even  
public static void Main()  
int num1, rem1;
Console.Write("Enter any Number: ");
num1= Convert.ToInt32(Console.ReadLine()); 
rem1 = num1 % 2;
if (rem1 == 0)
Console.WriteLine("{0} is an even number.\n",num1);
Console.WriteLine("{0} is an odd number.\n",num1);


Enter any Number: 10
10 is an even number

Code Explanation

  • Every Main method must be contained inside a class (Hello1 in this case).
  • The System.Console class contains a WriteLine method that can be used to display a string to the console.

Prev Tutorial Next Tutorial

Download Projects

Google Adsense Advertisements
Free Classified Site – Bedpage

Yahoo Advertisements