2-Amaliyot ishi ishlanmalari Amaliy mashgulot


Download 81.82 Kb.
Sana08.04.2023
Hajmi81.82 Kb.
#1341422
Bog'liq
21-variant


2-Amaliyot ishi ishlanmalari
Amaliy mashgulot. Kontеynеrlar (Kollеksiyalar) uchun amaliyot topshiriqlari uchun ishlanma va na’munalar.

21-variant


Array ning max elementi va min elementini toping.


#include
#include
#include


using namespace std;

int main()


{
array array = {5, 9, 16, 22, 30, 38, 47, 55, 63, 71};

auto max_it = max_element(array.begin(), array.end());


cout << "Maksimal element: " << *max_it << '\n';

auto min_it = min_element(array.begin(), array.end());


cout << "Minimal element: " << *min_it << '\n';


return 0;
}


listning har 2 ta elementidan keyin ularning yig‘indisini joylang.




#include
#include


using namespace std;

int main()


{
list my_list = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
list new_list;


for (auto it = my_list.begin(); it != prev(my_list.end()); advance(it, 2))
{
int sum = *it + *next(it);
new_list.push_back(*it);
new_list.push_back(*next(it));
new_list.push_back(sum);
if (next(next(it)) == my_list.end())
{
break;
}
}

new_list.push_back(my_list.back());




for (auto it = new_list.begin(); it != new_list.end(); ++it)
{
cout << *it << " ";
}
cout << endl;


return 0;
}



Download 81.82 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling