Enter a Number : 25 Entered Number is an Odd Number
This is a C# Program to check whether the entered number is even or odd.
This C# Program checks if a given integer is Odd or Even.
Here if a given number is divisible by 2 with the remainder 0 then the number is an Even number. If the number is not divisible by 2 then that number will be an Odd number.
Here is source code of the C# program which checks a given integer is odd or even. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Check whether the Entered Number is Even or Odd */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace check1 { class Program { static void Main(string[] args) { int i; Console.Write("Enter a Number : "); i = int.Parse(Console.ReadLine()); if (i % 2 == 0) { Console.Write("Entered Number is an Even Number"); Console.Read(); } else { Console.Write("Entered Number is an Odd Number"); Console.Read(); } } } }
In this C# program, we are reading the number using ‘i’ integer variable. If condition statement is used to check the number is even and odd. For even number the modulus of the value of ‘i’ variable by 2 is equal to zero, if the condition is true then print the statement as even number.
Otherwise, if the condition is false then execute the else statement, for odd number the modulus of the value of ‘i’ variable by 2 is not equal to zero, if the condition is true then execute the statement and print the statement as odd number.
Enter a Number : 25 Entered Number is an Odd Number