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

firdavs_mukhsimov_9f62550

Firdavs Mukhsimov

Posted on October 11, 2024

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

a) Quyidagi kodda if, else if, else qismi qanday ishlaydi?

int x = 10;
if (x < 5)
{
  Console. WriteLine("Less than 5");
}
else if (x == 10)
{
  Console. WriteLine("Equal to 10");
}
else
{
  Console WriteLine( "Greater than 5");
}

Harbiriga bitalab kirib tekshirib chiqadi
Enter fullscreen mode Exit fullscreen mode

b)Ternary operatorning sintaksisi ganday? Misol keltiring.

using System;

class Program
{
    static void Main()
    {
        int age = 20;
        string result = (age >= 18) ? "Voyaga yetgan" : "Voyaga yetmagan";
        Console.WriteLine(result);
    }
}
Enter fullscreen mode Exit fullscreen mode

c)Quyidagi kodda switch qismida qaysi natija chiqadi?

int day = 3;
switch (day)
{
  case 1:
     Console. WriteLine ("Monday") ;
     break;
  case 2:
     Console. WriteLine ("Tuesday");
     Break;
  case 3:
     Console. WriteLine ("Wednesday") ;
     break;
  default:
     Console WriteLine("Invalid day"); break;

Javob == Wednesday

Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
firdavs_mukhsimov_9f62550
Firdavs Mukhsimov

Posted on October 11, 2024

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

Sign up to receive the latest update from our blog.

Related