Labaratoriya 1
313-20 guruh talabasi Xushnazarov Azizbek
Topshiriq 1.
3
|
Ro’yxatdagi eng katta elementini aniqlang.
|
#include
#include
using namespace std;
int main() {
list mylist = { 1,9,-12,10,4,5,21 };
mylist.sort();
auto last = mylist.end();
last--;
cout << "Eng katta element : " << *last;
}
Natija:
Topshiriq 2.
7
|
Stek elementlari teskari tartibda joylashtirib chiqilsin.
|
#include
#include
using namespace std;
void reverse_stack(stack &the_stack) {
stack temp_stack;
for (;!the_stack.empty();) {
temp_stack.push(the_stack.top());
the_stack.pop();
}
the_stack = temp_stack;
}
void init_stack(stack &the_stack,initializer_list i_list) {
for (auto i:i_list) {
the_stack.push(i);
}
}
void show_stack(stack the_stack) {
for (;!the_stack.empty();) {
cout<
the_stack.pop();
}
cout << endl;
}
int main() {
stack mystack;
init_stack(mystack , { 0 , 2 , 3 , 4 , 1 , 12 , -45 , 32 } );
show_stack(mystack);
reverse_stack(mystack);
show_stack(mystack);
return 1;
}
Natija:____Topshiriq_3.'>Natija:
Topshiriq 3.
3.
|
Berilgan int turidagi to’plam qiymatlarining tublari 2- to’plamda nechta marta qatnashganligini aniqlovchi va ularni ekranga chiqaruvchi dastur tuzing. Ikkala to’plamdan ham bir xil qiymatli elemetlar o’chirilib Saralangan to’plam hosil qilinsin hamda uning qiymatlari ekranga chiqarilsin.
|
#include
#include
#include
using namespace std;
bool tubmi(int n) {
bool isPrime = true;
if (n == 0 || n == 1) {
isPrime = false;
}
else {
for (int i = 2; i <= n / 2; ++i) {
if (n % i == 0) {
isPrime = false;
break;
}
}
}
return isPrime;
}
int main()
{
vector vek1 = { 1,7,5,4,8,11,24,31 };
vector vek2 = { 90,1,23,10,7,11,20 };
int Count = 0;
for (auto itr = vek1.begin(); itr != vek1.end(); itr++) {
if (tubmi(*itr) && count(vek2.begin(), vek2.end(), *itr)) {
Count++;
}
}
cout << "count = " << Count << endl;
vector v3;
sort(vek1.begin(), vek1.end());
sort(vek2.begin(), vek2.end());
set_intersection(vek1.begin(), vek1.end(),
vek2.begin(), vek2.end(),
back_inserter(v3));
vector result;
for (auto itr = vek1.begin();itr != vek1.end();itr++) {
if (!count(v3.begin(), v3.end(), *itr)) {
result.push_back(*itr);
}
}
for (auto itr = vek2.begin();itr != vek2.end();itr++) {
if (!count(v3.begin(), v3.end(), *itr)) {
result.push_back(*itr);
}
}
for (auto i : result) {
cout << i << ",";
}
return 1;
}
Natija:
Topshiriq 4.
3
|
Talabalar haqida (familiya, ismi, sharfi, viloyat, tuman va qishloq) to’plam berilgan. Har bir viloyatda nechta talaba borligini aniqlovchi va viloya, tuman bo’yich talabalarni qidiruvchi dastur tuzing.
|
#include
#include
Do'stlaringiz bilan baham: |