Yangi konteynerlar hosil qiling, uni standart funksiyalar yordamida elementlar bilan to’lating va


Download 180.44 Kb.
Sana10.05.2020
Hajmi180.44 Kb.
#104643
Bog'liq
Yangi konteynerlar hosil qiling uni




  1. Yangi konteynerlar hosil qiling, uni standart funksiyalar yordamida elementlar bilan to’lating va  for_each funksiyasi yordamida uni chop qiling;

  2. Iteratorlardan foydalanib list konteyneri ustida amallar bajaring

  3. 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;



}


Download 180.44 Kb.

Do'stlaringiz bilan baham:




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