DEV Community

etibor2006
etibor2006

Posted on

TANLOV operatorlari.

_Bu operatorlar if_va else bolib ular masalalar ishlashda qo'l keladi.if() ichida beriladi.Bunda + - > < orqali shartlar beriladi.() ichida berganimizda hohlagancha berishimiz mumkin faqat gina ||(yoki)&&(va)!0(mumkin emas).Bular nima (||) bu belgi (yoki)bo'lib shartlar berganimizda bita tog'ri javob bo'lsa ham javob to'ri deb chiqaradi.(&&) bu belgi esa (va) bo'lib shart berganimizda bita javob notogri bolib qolsa ham notog'ri deb chiqaradi.(!0) bu belgi esa (mumkin emas) bo'lib shart berganimzda tog'ri javob kiritsak notog'ri deb beradi,notog'ri javob kiritsak tog'ri deb beradi.

_Else _ bu shartlar berganimizda qaysi javobga togri kelmasa sirazi else tushib cout ga nimabergan bolsak o'sha javob ekranga chiqadi.
_Bu operatorlarga doir misollar

#include <iostream> 
#include <iomanip>
#include <cmath>
using namespace std;
int main(){
int year;
  cin >> year;

  if(year % 400 == 0){
  cout <<  1;
  }
    else if(year % 4 == 0 && year % 100 == 0 && year % 400 != 0){
  cout <<  0;
  }else if(year % 4 == 0 && year % 100 != 0){
  cout <<  1;
  }else if(year % 4 != 0){
   cout << 0;   
  }

  return 0;
}
Enter fullscreen mode Exit fullscreen mode

_
Bu if else operatorlari har doim ham kerek .Chunki bu operatorlar har bir masala uchun ham kerak.

int main() {
int a,b;
  cin >> a >> b;
  if(a < b && a *a == b){
cout << a << '*' << a << '=' << b;
    }

 else if( a > b && a == b * b){
   cout << b << '*' << b << '='<< a;
 }
  else{
    cout << "none";
  }
}
Enter fullscreen mode Exit fullscreen mode

Masalar ishlaganimizda har doim ham if alohida qib yozishimz shartmas.Bizga sirazi bita javob kerek bolsa else ifqilib yozib ketsak ham bo'ladi.Bizni masalamiz faqatgina if da ishlanadigon bo'lsa ko'p sharlarni ichma ich ifqilib yozib ketsak ham bo'ladi.Bunga doir misolni ham korishingiz mumki.

#include <iostream>
using namespace std;
int main6(){
char belgi;
  cin >> belgi;
  if(belgi== 'l' || belgi == 'L'){
    cout << "Lions" ;
    if(belgi == 'e' || belgi == 'E'){
      cout <<  "Eagles";
       if (belgi == 'b'|| belgi == 'B'){
         cout << "Bears";

       }
    }
  }

 else{
   cout << "none";
 }

}
Enter fullscreen mode Exit fullscreen mode

@dawroun

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