Describe the function that in the new array will receive only positive values of the elements of the original array. Use the pointer engine.
Such code causes a bunch of errors, help to fix or find another way.
int *Create(int n) { int *a = new int[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } return a; } int *Filter(int *a, int &n) { int i, j, c; for (i = 0; i < n; i++) { c += (a[i] < 0); } int *b = new int[c]; for (i = 0, j = 0; i < n; i++) { if (a[i] < 0) b[j++] = a[i] { b[j++] = a[i] n = c; } } return b; } //Вывод массива void Write(int *a, int n) { for (i = 0; i < n; i++) { cout << setw(5) << a[i]; cout << endl; } } int n=10; int *a=Create(n); Write(a,n); int *b=Filter(a,n); Write(b,n);
if (a[i] < 0)- only positive ?? - Igor