Masala sharti: Ro’yxatdagi eng kichik elementini toping. Code
Download 29.1 Kb.
|
Dasturlash
- Bu sahifa navigatsiya:
- Masala sharti
Muhammad al-xorazmiy nomida Toshkent Axborot Texnalogiyalari univarsiteti 224-22 guruh talabasi Ahmadjonov Abduvohidning Dasturlash_2 fanidan bajargan Mustaqil ishi Topshirdi: Ahmadjonov Abduvohid Qabul qildi: Aliqulov Akmal Masala sharti: Ro’yxatdagi eng kichik elementini toping. Code: #include #include using namespace std; int findMin(list int min = lst.front(); for (auto it = lst.begin(); it != lst.end(); it++) { if (*it < min) { min = *it; } } return min; } void printList(list for (auto it = lst.begin(); it != lst.end(); it++) { cout << *it << " "; } cout << endl; } int main() { list int size; cout << "Ro'yxat hajmini kiriting: "; cin >> size; for(int i = 0; i < size; i++) { cout << "Iltimos, " << i+1 << "-sonni kiriting: "; int num; cin >> num; lst.push_back(num); } cout << "\nRo'yxat: "; printList(lst); int min = findMin(lst); cout << "\nEng kichik element: " << min << endl; return 0; } Masala sharti: Navbat o‘rtasidagi element o‘chirib tashlansin. Agar navbat elementlari soni toq bo‘lsa, bitta element, aks holda ikkita element o‘chirilsin Code: #include #include using namespace std; void removeMiddle(deque int main() { deque int n;
cin >> n; for (int i = 0; i < n; i++) { cout << "Iltimos, " << i+1 << "-sonni kiriting:"; int num; cin >> num; nums.push_back(num); } cout << "Deque: "; for (auto num : nums) { cout << num << " "; } cout << endl; removeMiddle(nums); cout << "Qolgan sonlar: "; for (auto num : nums) { cout << num << " "; } cout << endl; return 0; } Download 29.1 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling