Search This Blog

Saturday, 12 September 2015

To check the number odd or even without using modulas operator in C#

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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the number to check:");
            int num = Convert.ToInt32(Console.ReadLine());
            int num1 = num / 2;
            int num2 = num1;
            int num3 = num2 * 2;
            if (num3 == num)
            {
                Console.WriteLine("The number is even");
            }
            else
            {
                Console.WriteLine("The number is odd");
            }
            Console.ReadKey();
        }
    }

}

Output:
Enter the number to check: 10
The number is even

No comments:

Post a Comment