Enter the Number : 45 Entered Number is Not Divisible by 2
Users Online
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Latest Articles
Articles Hierarchy
C# Program to Check if a Number is Divisible by 2
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.
This C# Program Finds whether the Number is Divisible by 2.
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.
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 "); } else { Console.WriteLine("Entered Number is Not Divisible by 2"); } Console.ReadLine(); } } }
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.