|
Muhammad al xorazmiy nomidagi toshkent axborot texnologiyalari universiteti talabasi
|
tarix | 10.05.2022 | ölçüsü | 133,49 Kb. | | #57255 |
|
MUHAMMAD AL XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI TALABASI
Xudayberdiyev Asadbekning
Dasturlash fanidan bajargan
5-Laboratoriya ishi
14-variant
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;
}
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;
}
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;
}
Dostları ilə paylaş: |
|
|