Yangi konteynerlar hosil qiling, uni standart funksiyalar yordamida elementlar bilan to’lating va
tarix 29.05.2022 ölçüsü 180,44 Kb. #59978
Yangi konteynerlar hosil qiling, uni standart funksiyalar yordam
Yangi konteynerlar hosil qiling , uni standart funksiyalar yordamida elementlar bilan to’lating va for_each funksiyasi yordamida uni chop qiling ;
Iteratorlardan foydalanib list konteyneri ustida amallar bajaring
calloc () funksiyasidan foydalanib xotirani dinamik taqsimlashni amalga oshiring .
#include "stdafx.h"
#include
#include
#include
#include
#include
using namespace std ;
int main()
{
int n,x;
cout << "Listning o'lchamini kiriting: ";
cin >> n;
list bol;
for (int i = 0; i < n; i++){
x = rand() % 11 - 5;
bol.push_back(x);
cout << i + 1 << " - " << x<
}
for (int y : bol){ cout << y << endl; }
system("pause");
return 0;
}
b)
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
using namespace std;
void teskari(list const& list)
{
copy(list.rbegin(), list.rend(),
ostream_iterator(cout << " "));
cout << '\n';
}
int main()
{
int n,x;
cout << "Listning o'lchamini kiriting: ";
cin >> n;
list list;
for (int i = 0; i < n; i++){
x = rand() % 11 - 5;
list.push_back(x);
cout << i + 1 << " - " << x<
}
cout <
teskari(list);
system("pause");
return 0;
}
c)
#include
#include
using namespace std;
int main()
{
int n;
cout<<"elementlar sonini kiriting: ";
cin>>n;
int *ptr;
ptr = (int*) malloc(n*sizeof(int));
if(!ptr)
{
cout << "Memory Allocation Failed";
exit(1);
}
cout << "natijalar yuklanmoqda..." << endl << endl;
for (int i=0; i
{
ptr[i] = i*2+1;
}
cout << "yuklangan natijalar" << endl;
for (int i=0; i
{
cout << *(ptr+i) << endl;
}
return 0;
}
Dostları ilə paylaş: