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.
Enter the Number : 45 Entered Number is Not Divisible by 2
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Practice MCA MCQs
- Buy Computer Science Books
- Practice Computer Science MCQs
- Buy C# Books
- Apply for Computer Science Internship