Search This Blog

Wednesday 8 April 2015

Check whether the Entered Number is Even or Odd in C#

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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sample
{
    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.ReadLine();
        }
    }
}

Example:-

2)10(5
  10
--------
   0


 2)11(5
   10
--------
    1


 2)25(12
   2
--------
   05
    4
--------
    1


No comments:

Post a Comment