Introduction
In this snippet we will write a program to check whether the given number is even or odd.
What is Even/Odd number:
An Even number is an integer which is a multiple of two where as Odd number is an integer which is not a multiple of two. An integer that is not an odd number is an even number and vice- versa.
Example :
-4,-2,0,2,4,6,8,10... Even Numbers
-3,-1,1,3,5,7,9,11....... Odd Numbers
using System;
namespace DotNetMirror
{
class NumberIsEvenOrOdd
{
public static void Main()
{
int number;
Console.WriteLine("Program To check Whether Entered Number is Even or Odd");
Console.WriteLine("-----------------------------------------------------------");
Console.Write("Enter a Number: ");
number = int.Parse(Console.ReadLine());
CheckNumIsEvenOrOdd(number);
Console.ReadKey();
}
public static void CheckNumIsEvenOrOdd(int _number)
{
if (_number % 2 == 0)
{
Console.WriteLine("Number {0} is Even", _number);
}
else
{
Console.WriteLine("Number {0} is Odd", _number);
}
}
}
}
Output:
Program To check Whether Entered Number is Even or Odd
-----------------------------------------------------------
Enter a Number: 19
Number 19 is Odd