7. N o’lchamli to’plam berilgan. Bir bo’glamli ro’yhat hosil qilish. Ro’yhatga to’plam elementlarini qo’shish. Foydalanuvchi kiritgan elementni ro’yhatga qo’shish. Ro’yhatni ekranga chiqarish.
#include #include using namespace std;
int main() {
vector toplam = {1, 2, 3, 4, 5};
int element;
cout << "Ro'yhatga qo'shmoqchi bo'lgan elementni kiriting: ";
cin >> element;
toplam.push_back(element);
cout << "Ro'yhat elementlari: ";
for (int i = 0; i < toplam.size(); i++) {
cout << toplam[i] << " ";
}
return 0;
}
N ta elementdan tashkil topgan navbat berilgan.navbatning eng katta elementini o’chiring
#include
#include #include
int main() {
std::list myList;
int N;
std::cout << "Listga necha element qo'shmoqchisiz? ";
std::cin >> N;
for (int i = 0; i < N; ++i) {
int element;
std::cout << "Element #" << i + 1 << ": ";
std::cin >> element;
myList.push_back(element);
}
std::cout << "Boshlang'ich list: ";
for (int element : myList) {
std::cout << element << " ";
}
std::cout << std::endl;
if (!myList.empty()) {
auto maxElementIt = std::max_element(myList.begin(), myList.end());
myList.remove(*maxElementIt);
std::cout << "Yangi list: ";
for (int element : myList) {
std::cout << element << " ";
}
std::cout << std::endl;
} else {
std::cout << "List bo'sh. O'chirish amalga oshirilmadi." << std::endl;
}