Muhammad al xorazmiy nomidagi toshkent axborot texnologiyalari universiteti talabasi
Download 133.49 Kb.
|
5-lab
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 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()); 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 srand(time(0)); for (inti = 0; i< n; i++) { int m = rand()%33+1; A.push_back(m); } }
list 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++;
}
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]); }
return 0; } Download 133.49 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling