Satrli toifadagi vektor berilgan. Bir XIL qiymatdagi elementlarni aniqlang, ekranga chiqaring


Download 27.01 Kb.
Sana18.11.2023
Hajmi27.01 Kb.
#1785986
Bog'liq
MTA


1-amaliyot
Satrli toifadagi vektor berilgan. Bir xil qiymatdagi elementlarni aniqlang, ekranga chiqaring.
#include
#include
#include
using namespace std;
void fank(const vector& vec) {
set meet;
set fank;

for (int element : vec) {


if (meet.count(element) > 0) {
fank.insert(element);
} else {
meet.insert(element);
}
}
if (!fank.empty()) {
cout << "Bir xil qiymatli: ";
for (int element : fank) {
cout << element << " ";
}
cout <} else {
cout << "bir xil qiymatlani chiqaring:" << endl;
}
}
int main() {
vector numbers = {1, 2, 3, 4, 2, 5, 3, 6, 6, 7};

fank(numbers);

return 0;
}
2-amaliyot
P sonini oxiridan L sonini qo‘shuvchi funksiya tuzing.
#include
#include
using namespace std;
int main()
{
string p,l;
cin>>p>>l;
string S=p+l;
cout<}
5-amaliyot
Berilgan o’nlik natural sonni N (2≤N≤16) sanoq sistemasiga o’tkazuvchi rekursiv funksiya tuzing
#include
using namespace std;
void fank(int n, int b) {
if (n == 0) {
return;
}
fank(n / b, b);
int remainder = n % b;
if (remainder < 10) {
cout << remainder;
} else {
cout << char('A' + remainder - 10);
}
}

int main() {


int n;
int b;

cout << "O'nlik sonini kiriting: ";


cin >> n;

cout << "Bazani kiriting (2-16): ";


cin >> b;

cout << "Konvertatsiya qilingan soni: ";


(n, b);

return 0;


}
6-amaliyot
set — to‘plam doir misol ishlash

#include


#include
using namespace std;
int main() {
set fank;
fank.insert(5);
fank.insert(2);
fank.insert(8);
fank.insert(1);
cout << "Elementlarni kiritish:";
for (const auto & num :fank) {
cout << " " << num;
}
cout <int searchNum = 8;
if (fank.count(searchNum) > 0) {
cout << searchNum << " to'plamda mavjud." << endl;
} else {
cout << searchNum << " to'plamda mavjud emas." << endl;
}
int removeNum = 2;
fank.erase(removeNum);
cout << "Yangilangan elementlar:";
for (const auto& num : fank) {
cout << " " << num;
}
cout <return 0;
}
8. Ro’yhat nusxasini yarating.
#include
#include
using namespace std;
int main() {
list originalList = {1, 2, 3, 4, 5};
list copiedList(originalList.begin(), originalList.end());

cout << "Asl ro'yxat: ";


for (const auto& element : originalList) {
cout << element << " ";
}
cout <cout << "Nusxa olingan roʻyxat: ";
for (const auto& element : copiedList) {
cout << element << " ";
}
cout <return 0;


}
4.

Download 27.01 Kb.

Do'stlaringiz bilan baham:




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