1. Tarmoqlanuvci jarayonlarni dasturlash. Shartsiz o’tish operatori


N natural sonini kiritishni taklif qiluvchi programma tuzilsin. Agar natural bo’lmagan son kiritilsa, qayta kiritish taklif qilinsin


Download 27.22 Kb.
bet4/4
Sana29.04.2023
Hajmi27.22 Kb.
#1400797
1   2   3   4
Bog'liq
Berdikulov Oybek Mustaqil Ishi

N natural sonini kiritishni taklif qiluvchi programma tuzilsin. Agar natural bo’lmagan son kiritilsa, qayta kiritish taklif qilinsin.



  1. #include

  2. #include

  3. using namespace std;

  4. Int main()

  5. {

  6. float n;

  7. Nishon:

  8. cout << “natural son kiriting” << endl;

  9. cin >> n;

  10. if (( ceil(n) !=n) ||

  11. (n <= 0))

  12. goto nishon;

  13. cout << “Natural son kiritildi” << endl;

  14. return 0;

  15. }

2.Shartli o’tish operatori


Agar a sonini 2 ga bo'lganda qoldiq 0 ga teng bo'lsa, bu son juft, aks xolda toq.


#include
#include
int main()
{
int a;
cin>>a;
if (a%2==0)
cout<<"juft";
else
cout<<"toq";
return 0;
}


Qo’shimcha o’rganish uchun link.


https://www.tami.uz/matnga_qarang.php?id=1023


3.Tanlash operatori
Quyidagi misolda hafta kunlari nomini hisoblash uchun switch ish kunining raqami ishlatiladi:



  1. #include

  2. using namespace std;



  1. int main() {

  2. int day = 4;

  3. switch (day) {

  4. case 1:

  5. cout << "Dushanba";

  6. break;

  7. case 2:

  8. cout << "Seshanba";

  9. break;

  10. case 3:

  11. cout << "Chorshanba";

  12. break;

  13. case 4:

  14. cout << "Payshanba";

  15. break;

  16. case 5:

  17. cout << "Juma";

  18. break;

  19. case 6:

  20. cout << "Shanba";

  21. break;

  22. case 7:

  23. cout << "Yakshanba";

  24. break;

  25. }

  26. return 0;

  27. }



Ekranda Natija


Payshanba

Qoshimcha o’rganish uchun link




https://uzbekdevs.uz/darsliklar/cpp/cpp-da-switch-tanlash-operatori
Download 27.22 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling