Home >Backend Development >C#.Net Tutorial >C# program to determine whether a number is divisible by 2
If the remainder of dividing this number by 2 is 0, then it is divisible by 2.
Suppose our number is 5, we will use the following if-else to check it -
// 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"); }
Here is an example to determine if a number is divisible by 2 .
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(); } } }
Not divisible by 2
The above is the detailed content of C# program to determine whether a number is divisible by 2. For more information, please follow other related articles on the PHP Chinese website!