Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Sherzod5048
Sherzod5048

Posted on

     

C++ da shart operatori(if, else)

If statement Shart operatori shartlar boshqarilishini shartningtrue yokifalse ligiga qarab qaysi tartibda amalga oshirilishini ta'minlaydi.

Masala 1:

Agara sonini 2 ga bo'lganda qoldiq 0 ga teng bo'lsa, bu son juft, aks xolda toq:

#include<iostream>usingnamespacestd;intmain(){inta;cin>>a;if(a%2==0){cout<<"juft"}else{cout<<"toq"}return0;}
Enter fullscreen modeExit fullscreen mode
12juft
Enter fullscreen modeExit fullscreen mode

Bu codeda agarif ni ichidagi shart true bo'lsajuft,
aks xolda ya'ni false bo'lsatoq degan xabarni consolega chiqaradi.

Agar tekshirilayotgan shart nisbatan sodda bo'lsa, shart amalini? : ko'rinishida ishlatishimiz mumkun.
Masala 2:

2 ta son kiritilganda kattasini topuvchi programma tuzilsin:

#include<iostream>usingnamespacestd;intmain(){inta,b,max;cin>>a>>b;max=(a>b)?a:b;cout<<"Katta son : "<<max;return0;
Enter fullscreen modeExit fullscreen mode
1211Kattason:12
Enter fullscreen modeExit fullscreen mode

Bu code ham huddiif kabi vazifa bajarildi.2 son kiritildi vaa katta bo'lsab dan? - agar chiqara ni: - aks xoldaa kichkina bo'lsab danb ni chiqar deyildi va sonlarning kattasimax nomli uzgaruvchiga yuklandi.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Sherzod Jumayev
  • Joined

More fromSherzod5048

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp