Objects in this mirror are closer to Microsoft Technologies. DNM objective is to help users on Microsoft technologies by providing Articles, snippets, Interview Questions.

07 June 2012

.NET program to check whether the given number is even or odd


In this snippet we will write a program to 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

Program:

using System;
 
namespace Console_CSharp
{
    class NoIsEvenOrOdd
    {
        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:

 

0 Comments:

Post a Comment