একটি সংখ্যা 2 দ্বারা বিভাজ্য কিনা তা পরীক্ষা করার জন্য, আপনাকে প্রথমে অবশিষ্টটি খুঁজে বের করতে হবে।
যদি 2 দ্বারা ভাগ করা সংখ্যার অবশিষ্টাংশ 0 হয়, তাহলে এটি 2 দ্বারা বিভাজ্য হবে।
ধরা যাক আমাদের সংখ্যা 10, আমরা নিচের 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 = 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();
}
}
} আউটপুট
Divisible by 2