যদি 2 দ্বারা ভাগ করা হলে সংখ্যাটির অবশিষ্টাংশ 0 হয়, তাহলে এটি 2 দ্বারা বিভাজ্য হবে৷
ধরা যাক আমাদের সংখ্যা 5, আমরা নিচের 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");
} উদাহরণ
সংখ্যাটি 2 দ্বারা বিভাজ্য কি না তা খুঁজে বের করার জন্য নিম্নলিখিত একটি উদাহরণ৷
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