C# Program to find whether the Number is Divisible by 2


If the remainder of the number when it is divided by 2 is 0, then it would be divisible by 2.

Let’s say our number is 5, we will check it using the following if-else −

// checking if the number is divisible by 2 or not
if (num % 2 == 0) {
   Console.WriteLine("Divisible by 2 ");
} else {
   Console.WriteLine("Not divisible by 2");
}

Example

The following is an example to find whether the number is divisible by 2 or not.

Live Demo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
   class MyApplication {
      static void Main(string[] args) {
         int num;
         num = 5;
         // checking if the number is divisible by 2 or not
         if (num % 2 == 0) {
            Console.WriteLine("Divisible by 2 ");
         } else {
            Console.WriteLine("Not divisible by 2");
         }
         Console.ReadLine();
      }
   }
}

Output

Not divisible by 2

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 19-Jun-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements