Masalaning qo’yilishi
Download 37.8 Kb.
|
2 5312418952201111081
1-Variant. Aliboyev Umidjon Masalaning qo’yilishi 1) Yangi konteynerlar hosil qiling, uni standart funksiyalar yordamida elementlar bilan to’lating va for_each funksiyasi yordamida uni chop qiling; #include #include #include using namespace std; void show(int i) { std::cout << i << " "; } int main() { vector v.push_back(1); v.push_back(2); v.push_back(3); v.push_back(5); for_each(v.begin(), v.end(), show); cout << "\n"; return 0; } 2) Iteratorlardan foydalanib list konteyneri ustida amallar bajaring #include #include #include using namespace std; int main() { list for (int i = 0; i < 99; i++) { myList.push_back(i); }
copy(myList.begin(), myList.end(), ostream_iterator cout << "\nbirinchi element: " << myList.front(); cout << "\nikkinchi element: " << myList.back(); return 0; } 3) calloc () funksiyasidan foydalanib xotirani dinamik taqsimlashni amalga oshiring . #include #include using namespace std; int main() { int n;
std::cout << ("elementlar soni: "); std::cin >> n; int* sonlar = (int*)calloc(n, sizeof(int)); if (sonlar == NULL) exit(1); for (int i = 0; i < n; i++) { std::cout << ("elementni kiriting: "); std::cin >> sonlar[i]; } std::cout << "xotiraga olingan elementlar: "; for (int i = 0; i < n; i++) { std::cout << sonlar[i] << " "; } return 0; } Download 37.8 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling