
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Write a C# program to check if a number is divisible by 2
To check if a number is divisible by2 or not, you need to first find the remainder.
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 10, 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"); }
The following is an example to find whether the number is divisible by 2 or not −
Example
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { class MyApplication { static void Main(string[] args) { int num; num = 10; // 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
Divisible by 2
- Related Articles
- C Program to check if a number is divisible by sum of its digits
- C Program to check if a number is divisible by any of its digits
- Check if a large number is divisible by 20 in C++
- Check if a large number is divisible by 2, 3 and 5 or not in C++
- Check if a number is divisible by 23 or not in C++
- Check if a number is divisible by 41 or not in C++
- Write a C# program to check if the entered number is Armstrong number?
- Write a C# program to check if a number is Palindrome or not
- Write a C# program to check if a number is prime or not
- Check if a large number is divisible by 11 or not in C++
- Check if a large number is divisible by 25 or not in C++
- Check if a large number is divisible by 3 or not in C++
- Check if a large number is divisible by 5 or not in C++
- Check if a large number is divisible by 75 or not in C++
- Check if a large number is divisible by 8 or not in C++

Advertisements