Muhammad al xorazmiy nomidagi toshkent axborot texnologiyalari universiteti talabasi


Download 133.49 Kb.
Sana29.05.2020
Hajmi133.49 Kb.
#111379
Bog'liq
5-lab


MUHAMMAD AL XORAZMIY NOMIDAGI

TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI TALABASI

Xudayberdiyev Asadbekning

Dasturlash fanidan bajargan

5-Laboratoriya ishi

14-variant



  1. Yangi konteynerlar hosil qiling, uni standart funksiyala ryordamida elementlar bilan to’lating reverse funksiyasi yordamida amallar bajaring;

#include

#include

#include

#include

using namespace std;

intmain() {

srand(time(0));

vector vec;

int n, m, q=1;

cout<< "Elementlarsoninikiriting: ";

cin>> n; cin.ignore();

printf("\nRo`yxat: \n");

for (inti = 0; i< n; i++) {

m = rand() % 55 + 1;

vec.push_back(m);

cout< " << m <

}

reverse(vec.begin(), vec.end());



printf("\n***NATIJA***\n");

for (inti :vec) {

cout<< q << " -> " <

q++;


}

getchar();

return 0;

}


  1. Iteratorlardan foydalanib list konteyneri ustida amallar bajaring;

#include

#include

#include

#include

using namespace std;

void list_set(list& A, int n) {

srand(time(0));

for (inti = 0; i< n; i++) {

int m = rand()%33+1;

A.push_back(m);

}

}

intmain() {



list a;

int n, m=1;

cout<< "\nElementlarsoninikiriting: "; cin>> n;

cin.ignore();

list_set(a, n);

printf("\nKonteynerelementlari\n\n");

for (auto it = a.begin(); it != a.end(); ++it) {

cout<< m << " -> " << *it <

m++;

}

auto s = a.begin();



int sum=0;

while (s != a.end()) {

sum += *s;

++s;


}

printf("\nBarchaelementlaryig`indisi: %d", sum);

getchar();

return 0;

}


  1. malloc () funksiyasidan foydalanib xotirani dinamik taqsimlashni amalga oshiring .

#include

#include

#include

using namespace std;

intmain() {

int* q;


int n, i;

cout<< "Elementlarsoninikiriting: ";

cin>> n; cin.ignore();

q = (int*)malloc(n* sizeof(int));

if (*q != 0) {

printf("\nXotiraajratildi.\n");

}

else


{

printf("\nXotiraajratilmadi.\n");

}

printf("\nElementlar\n");



for (inti = 0; i< n; i++) {

q[i] = (i + 1) * 3;

printf(" %d\n", q[i]);

}

getchar();



return 0;

}




Download 133.49 Kb.

Do'stlaringiz bilan baham:




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