यदि संख्या को 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