Allambergenov Dilmurod
Shart operatoriga oid misollar
Download 0.52 Mb.
|
1 2
Bog'liqAllambergenov Dilmurod с
- Bu sahifa navigatsiya:
- Tanlash operatoriga oid misollar
- For sikl operatoriga oid misollar
- Shart sikl operatoriga oid misollar
- Minimum va maksimumga oid misollar
- Bir o’lchamli massiv bilan ishlash
- Massiv elementlarini chiqarish
Shart operatoriga oid misollar
Sonlarni taqqoslash (sodda) misol #include using namespace std; int main() { int x = 20; int y = 18; if (x > y) { cout << "x y da katta"; } return 0; } Keyingi misol, inglizlardagi vaqtga qarab salomlashishni topish #include using namespace std; int main() { int time = 20; if (time < 18) { cout << "Good day."; } else { cout << "Good evening."; } return 0; } Tanlash operatoriga oid misollar Haftaning raqamiga qarab qaysi hafta kuni ekanini aniqlovchi dastur #include using namespace std; int main() { int day = 4; switch (day) { case 1: cout << "Dushanba"; break; case 2: cout << "Seshanba"; break; case 3: cout << "Chorshanba"; break; case 4: cout << "Payshanba"; break; case 5: cout << "Juma"; break; case 6: cout << "Shanba"; break; case 7: cout << "Yakshanba"; break; } return 0; } For sikl operatoriga oid misollar 10 gacha sonlar orasidan juft sonlarni chiqaruvchi dastur #include using namespace std; int main() { for (int i = 0; i <= 10; i = i + 2) { cout << i << "\n"; } return 0; } Shart sikl operatoriga oid misollar Bunda for siklining ichida if else shartlari joylashgan bo’ladi #include int main(void) { int answer, i; int right, wrong; right = 0; wrong = 0; for( i = 1; i < 11; i = i + 1) { printf("What is %d + %d? ", i, i); scanf("%d", &answer); if(answer == i + i) { printf("Right! "); right++; } else { printf("Sorry, you're wrong. "); printf("The answer is %d. ", i + i); wrong++; } } printf("You got %d right and %d wrong.", right, wrong); return 0; } Minimum va maksimumga oid misollar Massivdagi max va min qiymatlarni topuvchi dastur #include using namespace std; int main () { int arr[10], n, i, max, min; cout << "Massiv hajmi : "; cin >> n; cout << "Enter the elements of the array : "; for (i = 0; i < n; i++) cin >> arr[i]; max = arr[0]; for (i = 0; i < n; i++) { if (max < arr[i]) max = arr[i]; } min = arr[0]; for (i = 0; i < n; i++) { if (min > arr[i]) min = arr[i]; } cout << "Max : " << max; cout << "Min : " << min; return 0; } Bir o’lchamli massiv bilan ishlash Massiv elementlarini o’zgartirish #include #include using namespace std; int main() { string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"}; cars[0] = "Opel"; cout << cars[0]; return 0; } Massiv elementlarini chiqarish #include #include using namespace std; int main() { string cars[5] = {"Volvo", "BMW", "Ford", "Mazda", "Tesla"}; for (int i = 0; i < 5; i++) { cout << cars[i] << "\n"; } return 0; } Download 0.52 Mb. Do'stlaringiz bilan baham: |
1 2
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling