C# Program to Check if a Number is Divisible by 2

This is a C# Program to find whether the number is divisible by 2.

Problem Description

This C# Program Finds whether the Number is Divisible by 2.

Problem Solution

Any whole number that ends in 0, 2, 4, 6, or 8 will be divisible by 2.Here the divisibility test is done by performing the mod function with 2.

Program/Source Code

Here is source code of the C# Program to Find whether the Number is Divisible by 2. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

 *  C# Program to Find whether the Number is Divisible by 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication16
    class Program
        static void Main(string[] args)
            int n;
            Console.WriteLine("Enter the Number :");
            n = int.Parse(Console.ReadLine());
            if (n % 2 == 0)
                Console.WriteLine("Entered Number is Divisible by 2 ");
                Console.WriteLine("Entered Number is Not Divisible by 2");
Program Explanation

In this C# program, we are reading the number using ‘n’ variable. If condition is used to check that the modulus of the value of ‘n’ variable by 2 is equal to 0. If the condition is true then execute the statement. Print the statement as the number is divisible by 2. Otherwise, if the condition is false, then execute the else statement and print the statement as not divisible by 2.

Runtime Test Cases
Enter the Number :
Entered Number is Not Divisible by 2

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.