28. Operators(if, else if, else, ternary operator, switch)

zahro_11eecc01a1cfe5142b9

Zahro

Posted on October 16, 2024

28. Operators(if, else if, else, ternary operator, switch)

a) Quyidagi kodning natijasi:

int score = 85;
if (score >= 90)
{
    Console.WriteLine("A");
}
else if (score >= 80)
{
    Console.WriteLine("B");
}
else if (score >= 70)
{
    Console.WriteLine("C");
}
else
{
    Console.WriteLine("F");
}
Enter fullscreen mode Exit fullscreen mode

Bu yerda score = 85 bo'lganligi sababli, kod else if (score >= 80) blokiga kiradi va natija:B

b) Switch operatoridan foydalanib 5 ga bo'linish natijasini chiqaruvchi kod:

int x = 5;

switch (x % 5)
{
    case 0:
        Console.WriteLine($"{x} is divisible by 5");
        break;
    default:
        Console.WriteLine($"{x} is not divisible by 5");
        break;
}
Enter fullscreen mode Exit fullscreen mode

Agar x = 5 bo'lsa, natija:

5 is divisible by 5

💖 💪 🙅 🚩
zahro_11eecc01a1cfe5142b9
Zahro

Posted on October 16, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related