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;
}