DEV Community

Muhammadyusuf
Muhammadyusuf

Posted on • Updated on

9-dars

(#include <iostream>)
using namespace std;
int main (){
int son;
    cin >> son;
    if(son > 0 )
cout << son << "musbat";   
else if(son < 0){
    cout << son << "manfiy";
}
else
    cout << son << "zero";

return 0;  
}
Enter fullscreen mode Exit fullscreen mode

bu kod bugun yozgankudimiz.
1 - qator include kutubhona chaqirish.
2 - qator std kudi .
3 - qator kudi int kudi.
4 - qator kudi intga kirg'iziladigon nom.
5 - qator cin kudi bu kod har bitta inddankeyin quyiladigonkod.
6 - qator if kudi (son > 0 )bu kod esa agar agar intdan son utibketadigon bolsa yoki pasayib ketadigonini bildirib turadi.
7 - qator agar son aytilganibilan birhilbolsa musbatsozini chiqaradi.
8 - qator bu else if bu degani qanday buyrug'ingiz bolsa bersangiz bolaveradi.
9 - qator cout buyruq beradigon kod agar bu kodni yozgandan keyin bironta hoto chiqasa soz yozibqoysangiz boladi.
10 - qator else agar ifga buyruqberganingngizda u hoto chiqsa bildirib turadi.
10 - qator qaytarish 0marta degani .

MAVZU IF ELSE
Enter fullscreen mode Exit fullscreen mode

uzi if else degani nima degani ?
if else bironta buyruqbersangiz uni tug'ri yokigin notug;riligini bildiradi agar siznig kudingiz notug'ri chiqsa siraziga else otadi ! agar tug'ri bolsa if ichidagi charni qiqaribberadi.

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.

Top comments (0)