Toq uzinlikdagi to’plamning birinchi elementini 4 marotaba takrorlab


Download 29.82 Kb.
Sana13.04.2023
Hajmi29.82 Kb.
#1353044

AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI TALABASITEMIROV AMIRXONNING DASTURLASH 2 FANIDAN 3-LABARATORIYA ISHI
  1. 31. Berilgan char turidagi to’plamning juft uzinlikka ega bo’lgan elementlarining oxirgi elementini 5 marotaba takrorlab, 2- to’plamni, toq uzinlikdagi to’plamning birinchi elementini 4 marotaba takrorlab, 3- to’plamni hosil qiluvchi va ularni ekranga chiqaruvchi dastur tuzing.


#include #include #include using namespace std;




void print_multiset(multiset s)
{
for (auto i : s)
{
cout << i << " ";
}
cout << endl;
}

int main()


{
multiset s1 = {'a', 'b', 'c', 'd', 'e', 'f'};
multiset s2 = {'a', 'b', 'c', 'd', 'e'}; multiset s3;

cout << "To'plam #1: "; print_multiset(s1); cout << "To'plam #2: "; print_multiset(s1);


auto it = s1.end(); it--;


char last = *it;
for (int i = 0; i < 5; i++)
{
s3.insert(last);
}


it = s2.begin(); char first = *it;
for (int i = 0; i < 4; i++)
{
s3.insert(first);
}

cout << "To'plam #3: "; print_multiset(s3);




return 0;
}


  1. 31. Berilgan to’plam toq o’rindagi elementlaridan 2- to’plam hosil qilinsin, birinchi to’plamning toq o’rindagi elementlari o’chirilsin. Hamda ikki to’plam elementlari ekranga chop etilsin.




#include #include
using namespace std;


void print_set(set s)
{
for (auto i : s)
{
cout << i << " ";
}
cout << endl;
}

int main()


{
set s1 = {'a', 'b', 'c', 'd', 'e', 'f'}; set s2;


for (auto i = s1.begin(); i != s1.end(); i++)
{
if (*i % 2 == 1)
{
s2.insert(*i); s1.erase(i++);
}
}
cout << "To'plam #1: "; print_set(s1);
cout << "To'plam #2: "; print_set(s2);


return 0;
}

Download 29.82 Kb.

Do'stlaringiz bilan baham:




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