DEV Community

Muhammadyusuf
Muhammadyusuf

Posted on

1

10-dars

int x = 20;
int y = 18;
if (x > y) {
  cout << "x is greater than y";
}

Enter fullscreen mode Exit fullscreen mode

Yuqoridagi misolda x ning y dan katta ekanligini tekshirish uchun ikkita o'zgaruvchidan foydalanamiz, x va y> ( operator yordamida). X 20, y 18 va biz 20 ning 18 dan katta ekanligini bilamiz, biz ekranga "x y dan katta" deb chop etamiz.

int time = 20;
if (time < 18) {
  cout << "Good day.";
} else {
  cout << "Good evening.";
}
// Outputs "Good evening."

Enter fullscreen mode Exit fullscreen mode

Yuqoridagi misolda vaqt (20) 18 dan katta, shuning uchun shart false. Shu sababli, biz shartga o'tamiz elseva "Xayrli oqshom" ekraniga chop etamiz. Agar vaqt 18 dan kam bo'lsa, dastur "Xayrli kun" ni chop etardi.

int time = 22;
if (time < 10) {
  cout << "Good morning.";
} else if (time < 20) {
  cout << "Good day.";
} else {
  cout << "Good evening.";
}
Enter fullscreen mode Exit fullscreen mode

Yuqoridagi misolda vaqt (22) 10 dan katta, shuning uchun birinchi shartfalse . Izohdagi keyingi shart else ifham false, shuning uchun biz shartga o'tamiz, else chunki 1-shart va 2-shart ikkalasi false- va ekranga "Xayrli oqshom" ni chop qilamiz.

Biroq, agar vaqt 14 bo'lsa, bizning dasturimiz "Xayrli kun" ni chop etardi.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay