• Misol 2
  • 12 system ("pause"); 13 return 0; 14 } Misol 3
  • 8 cout 9 while (x != y) 10 { 11 cin >> y; 12 u++;
  • 16 cout 17 cout 18 system ("pause"); 19 return 0; 20 }
  • while
  • Misol 1: 1 dan 10 gacha bo'lgan sonlarni chiqaruvchi dastur tuzilsin. 1 #include




    Download 15,08 Mb.
    bet65/135
    Sana22.05.2024
    Hajmi15,08 Mb.
    #250347
    1   ...   61   62   63   64   65   66   67   68   ...   135
    Bog'liq
    Fizik jarayonlarni kompyuterda modellashtirish

    Misol 1: 1 dan 10 gacha bo'lgan sonlarni chiqaruvchi dastur tuzilsin.
    1 #include
    2 int main()
    3 {
    4 int i = 1;
    5 while ( i <=10 ) 
    6 {
    7 cout << i << endl;
    8 i++;
    9 }
    10 system ("pause");
    11 return 0;
    12 }
    Misol 2: 1+1/2+1/3+…+1/50 yig`indini hisoblovchi dastur tuzilsin.
    1 #include
    2 int main()
    3 {
    4 float i = 1; // sanagich
    5 float s = 0; // yig'indi
    6 while ( i <= 50 )
    7{
    8 s += 1 / i;
    9 i++;
    10 }
    11 cout << s << endl;
    12 system ("pause");
    13 return 0;
    14 }
    Misol 3: Kompyuter o'ylagan sonni topish dasturi
    1 #include
    2 #include
    3 int main()
    4 {
    5 int x, y = 0, u = 0;
    6 srand(time(NULL));
    7 x ==rand() % 1000 + 1;
    8 cout << "Kompyuter o'ylagan sonni toping" << endl;
    9 while (x != y)
    10 {
    11 cin >> y;
    12 u++;
    13 if (x > y) cout << "Kompyuter o'ylagan son katta" << endl;
    14 else if (x < y) cout << "Kompyuter o'ylagan son kichik" << endl;
    15 }
    16 cout << "Qoyil topdingiz!!!" << endl;
    17 cout << "Urinishlar soni=" << u << endl;
    18 system ("pause");
    19 return 0;
    20 }
    Kelinglar yana materialni takrolashni misollarda ko’ramiz:

    C++ Takrorlash Operatori (While, Do While)


    Assalomu alaykum bugun siz bilan takrorlash operatorlari qanchalik ahamiyatga ega ekanligni o'rganamiz. Siz tasavvur qiling, tizim yaratdingiz bu tizimga kirish uchun login parol tekshirmoqchisiz? login parolni mosligini tekshirish uchun ushbu takrorlash operatorlari juda qo'l keladi (Unutmang login parolni tekshirish uchun takrorlash operatorlaridan foydalanish optimal yo'l emas).
    Takrorlash qadamini amalga oshirish uchun while kalit so'zidan foydalanamiz. shart orqali tskil hosil bo'ladi. quyidagi sintaksisni o'zingizga formula sifatida yodlab quying.

    Download 15,08 Mb.
    1   ...   61   62   63   64   65   66   67   68   ...   135




    Download 15,08 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Misol 1: 1 dan 10 gacha bo'lgan sonlarni chiqaruvchi dastur tuzilsin. 1 #include

    Download 15,08 Mb.