TANLOV operatorlari.

etibor2006

etibor2006

Posted on February 8, 2023

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

💖 💪 🙅 🚩
etibor2006
etibor2006

Posted on February 8, 2023

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

Sign up to receive the latest update from our blog.

Related