• C++ Shart Operatori
  • IF (Agar)
  • Fizik jarayonlarni kompyuterda modellashtirish




    Download 15,08 Mb.
    bet59/135
    Sana22.05.2024
    Hajmi15,08 Mb.
    #250347
    1   ...   55   56   57   58   59   60   61   62   ...   135
    Bog'liq
    Fizik jarayonlarni kompyuterda modellashtirish

    Dastur С++ da

    Dastur Pythonda

    1 #include
    2 #include
    3 using namescape std;
    4 int main ()
    5 { i
    6 int n;
    7 cout << “N=”;
    8 cin >> n;
    9 switch (n)
    10 {
    11 case 1: cout<< “Dushanba”;
    12 break;
    13 case 2: cout<< “Seshanba”;
    14 break;
    15 case 3: cout<< “Chorshanba”;
    16 break;
    17 case 4: cout<< “Payshanba”;
    18 break;
    19 case 5: cout<< “Juma”; break;
    20 case 6: cout<< “Shanba”;
    21 break;
    22 case 7: cout<< “Yakshanba”;
    23 break;
    24 default: cout << “Adashdingiz!” ;
    25}
    26 return 0;
    27}



    1 import datatime//
    2 day=int(input(“n/sonni kiriting=?”))
    3 x=datetime.datetime(Day)
    4 print(“1-Dushanba, 2-Seshanba, 3-Chorshanba, 4-Payshanba, 5-Juma, 6-Shanba, 7-Yakshanba/n”)
    5 if x=1 print(“Dushanba”)
    6 if x=2 print(“Seshanba”)
    7 if x=3 print(“Chorshanba”)
    8 if x=4 print(“Payshanba”)
    9 if x=5 print(“Juma”)
    10 if x=6 print(“Shanba”)
    11 if x=7 print(“Yakshanba”)
    12 print(x.strftime(%w))


    har bir case ga mos ko‟rsatmalar ketma-ketligi oxirida yozilgan break operatori shu ko‟rsatmalar ketma-ketligi bajarilgandan song tanlash operatoridan chiqishni ta‟minlaydi.


    1 #include
    2 using namescape std;
    3 int main ()
    4 {
    5 int n;
    6 cout << “N=”;
    7 cin >> n;
    8 switch (n)
    9 {
    10 case 1: cout<< “Dushanba”;
    11 break;
    12 case 2: cout<< “Seshanba”;
    13 break;
    14 case 3:
    15 cout<< “Chorshanba”;
    16 break;
    17 case 4: cout<< “Payshanba”;
    18 break;
    19 case 5: cout<< “Juma”;
    20 break;
    21 case 6: cout<< “Shanba”;
    22 break;
    23 case 7: cout<< “Yakshanba”;
    24 break;
    25 default: cout << “Adashdingiz!” <<<

    Rasm 35. Hafta kunlarini ekranga chiqarish dasturining algoritmining blok Sxemasi.

    C++ Shart Operatori


    Assalomu Alaykum bugun siz bilan shart operatori haqida gaplashib olamiz. Shart operatori juda kerak hisoblanadi. Tizimga kirishda server yaratganizda ushbu shart operatoridan foydalanish ehtimolingiz 80% ni tashkil qiladi.
    C++ dasturlash tilida matematikada qo'llaniladigan odatiy mantiqiy shartlarni qo'llab quvvatlaydi.

    • Kamroq: a

    • Kam yoki teng: a <= b

    • Kattaroq: a> b

    • Kattaroq yoki teng: a> = b

    • a == b ga teng

    • Teng emas: a! = b

    C ++ quyidagi shartli iboralarga ega:

    1. ifAgar belgilangan shart rost bo'lsa, bajarilishi kerak bo'lgan kod blokini belgilash uchun foydalaning

    2. elseAgar bir xil shart noto'g'ri bo'lsa, bajarilishi kerak bo'lgan kod blokini belgilash uchun foydalaning

    3. else ifAgar birinchi shart noto'g'ri bo'lsa, sinov qilish uchun yangi shartni belgilash uchun foydalaning

    4. switchAmalga oshiriladigan ko'plab alternativ kod bloklarini belgilash uchun foydalaning

    IF (Agar)


    ifAgar shart bo'lsa, bajarilishi kerak bo'lgan C ++ kodi blokini belgilash uchun bayonnomadan foydalaning true
    .
    if () {
    // Faqat to'g'ri bo'lgandagi holatni yozasiz
    }
    E'tibor bering, if kichik harflar bilan. Katta harflar (If yoki IF) xato keltirib chiqaradi.
    Quyidagi misolda, 15 ning 13 dan katta ekanligini aniqlash uchun ikkita qiymatni sinab ko'ramiz, agar shart bo'lsa true, ba'zi matnlarni chop eting:
    1 #include
    2 using namespace std;


    Download 15,08 Mb.
    1   ...   55   56   57   58   59   60   61   62   ...   135




    Download 15,08 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Fizik jarayonlarni kompyuterda modellashtirish

    Download 15,08 Mb.