return 0;
}
7. Ro’yxat berilgan uning juft qiymatdagi elementlarini ekranga chiqaring.
#include #include #include using namespace std;
int main() {
srand(time(0));
int n, j = 0;
cout << "Ro'yhat elementlari soni: "; cin >> n;
list a;
for (int j = 0; j < n; j++) {
a.push_back(rand() % 50 - 20);
}
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
cout << endl;
for (auto i = a.begin(); i != a.end(); i++) {
if (j % 2 != 0)
cout << *i << " ";
j++;
}
_getwch();
return 0;}
8.Ro‘yxatdagi oxirgi elementga ko‘rsatkich qaytaruvchi funksiya yozing.
#include #include #include using namespace std;
int main() {
srand(time(NULL));
int n, x;
cout << "Ro'yhat elementlari soni: "; cin >> n;
list a;
for (int j = 0; j < n; j++) {
a.push_back(rand() % 50 - 20);
}
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
cout << endl;
auto nx = next(a.end(), -1);
cout << *nx << '\n';
_getwch();
return 0;}
9. Ro’yxat berilgan ekrandan kiritilgan so’zga teng bo’lgan elementi bor yo’qligini aniqlang.
#include #include #include
using namespace std;
int main() {
int n;
cout << "Ro'yhat elementlari soni: "; cin >> n;
list a;
string k,l;
for (int i = 1; i <= n; i++) {
cin >> k;
a.push_back(k);
}
cout << "Qidirayotgan so'z kiriting: "; cin >> l;
for (auto i = a.begin(); i != a.end(); i++) {
if (*i == l)
cout << "Bor";
}
_getwch();
return 0;
}
10. Birinchi elementni har qanday turdagi elementlari uchun ro‘yxatdan olib tashlaydigan funksiyani yozing.
#include #include #include
using namespace std;
int main() {
srand(time(NULL));
int n, x;
cout << "Ro'yhat elementlari soni: "; cin >> n;
list a;
for (int j = 0; j < n; j++) {
a.push_back(rand() % 50 - 20);
}
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
cout << endl;
auto nx = next(a.begin(), 0);
a.remove(*nx);
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
_getwch();
return 0;
}
11. Barcha ro‘yxat elementlarini ekranga chop etuvchi funksiyani yozing.
#include #include #include using namespace std;
int main() {
srand(time(NULL));
int n;
cout << "Ro'yhat elementlari soni: "; cin >> n;
list a;
for (int j = 0; j < n; j++) {
a.push_back(rand() % 50 - 20); }
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " "; }
_getwch();
return 0;}
12. Ro’yxat berilgan ekrandan kiritilgan songa teng bo’lgan elementlarni toping.
#include #include #include using namespace std;
int main() {
srand(time(NULL));
int n,x;
cout << "Ro'yhat elementlari soni: "; cin >> n;
list a;
for (int j = 0; j < n; j++) {
a.push_back(rand() % 50 - 20); }
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " "; }
cout << "\nSon kiriting: "; cin >> x;
for (auto i = a.begin(); i != a.end(); i++) {
if (x == *i)
cout << *i << " "; }
_getwch();
return 0;}
13. Ro‘yxatning nusxasini qurish, lekin teskari tartibda.
#include #include #include using namespace std;
int main() {
srand(time(NULL));
int n, x;
cout << "Ro'yhat elementlari soni: "; cin >> n;
list a, b;
for (int j = 0; j < n; j++) {
a.push_back(rand() % 50 - 20);
}
cout << "Birinchi ro'yhat: ";
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
b.push_front(*i);
}
cout << "\nIkkinchi ro'yhat: ";
for (auto i = b.begin(); i != b.end(); i++) {
cout << *i << " ";
}
_getwch();
return 0; }
14.VECTOR hosil qiling elementlarini kamayish tartibida saralang.
#include #include #include #include #include
using namespace std;
int main() {
srand(time(NULL));
int n;
cout << "Vector elementlari soni: "; cin >> n;
vector a;
for (int i = 0; i < n; i++) {
a.push_back(rand() % 50 - 20);
}
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
sort(a.begin(), a.end(), greater ());
cout << endl;
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
_getwch();
return 0;
}
15.VECTOR hosil qiling elementlarini o’sish tartibida saralang.
#include #include #include #include #include using namespace std;
int main() {
srand(time(NULL));
int n;
cout << "Vector elementlari soni: "; cin >> n;
vector a;
for (int i = 0; i < n; i++) {
a.push_back(rand() % 50 - 20);
}
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
sort(a.begin(), a.end());
cout << endl;
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
_getwch();
return 0;
}
16.VECTOR elementlaridan birinchi uchragan manfiy elementini chop qiling.
#include #include #include
using namespace std;
int main() {
srand(time(NULL));
vector a;
int n,k=1;
cout << "Vector elementlari soni: "; cin >> n;
for (int i = 0; i < n; i++) {
a.push_back(rand() % 50 - 20);
}
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
cout << endl;
for (auto i = a.begin(); i != a.end(); i++) {
if (*i < 0 && k == 1) {
cout << *i << " ";
k++; } }
_getwch();
return 0; }
17. VECTOR hosil qiling va uning tub elementlarini yig’indisini toping.
#include #include #include
using namespace std;
int main() {
srand(time(NULL));
vector a;
int n, k = 1, s = 0;
cout << "Vector elementlari soni: "; cin >> n;
for (int i = 0; i < n; i++) {
a.push_back(rand() % 50 );
}
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
cout << endl;
for (int i = 0; i < n; i++) {
k = 1;
for (int j = 1; j <= a.at(i); j++) {
if (a.at(i) % j == 0)
k++;
}
if (k == 3) {
s += a.at(i);
}
}
cout << s;
_getwch();
return 0;}
18.VECTOR hosil qiling va uning toq qiymatdagi elementlarini yig’indisini toping
#include #include #include using namespace std;
int main() {
srand(time(NULL));
vector a;
int n, k = 1, s = 0;
cout << "Vector elementlari soni: "; cin >> n;
for (int i = 0; i < n; i++) {
a.push_back(rand() % 50);
}
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " ";
}
cout << endl;
for (int i = 0; i < n; i++) {
if (a.at(i) % 2 != 0) {
s += a.at(i);
}
}
cout << s;
_getwch();
return 0;}
19. VECTOR hosil qiling va uning mukammal son bo’lgan i elementlarini ko’paytmasini toping.
#include #include #include using namespace std;
int main() {
srand(time(NULL));
vector a;
int n, k = 1, s = 0, s1 = 1;
cout << "Vector elementlari soni: "; cin >> n;
for (int i = 0; i < n; i++) {
a.push_back(rand() % 50); }
for (auto i = a.begin(); i != a.end(); i++) {
cout << *i << " "; }
cout << endl;
for (int i = 0; i < n; i++) {
s = 0;
for (int j = 1; j < a.at(i); j++) {
if (a.at(i) % j == 0) {
s += j; } }
if (s == a.at(i)) {
cout << a.at(i) << " ";
s1 *= a.at(i); }
}
cout << endl;
cout << s1;
_getwch();
return 0;
}
20. VECTOR hosil qiling va 7 ga karrali elementlar sonini uning yig’indisiga nisbati topilsin.