Write a function that receives a pointer to an array and its size. The function should remove all prime numbers from the array and return a pointer to the new array. Why does the program display garbage? If you can comment on the errors, please.
#include<iostream> #include <cmath> using namespace std; int prostae_chislo(int n){ int f = 1; if ((n==2)||(n==3)) f=1; else{ for (int i = 2; i < floor(sqrt(n)); i++) if (n % i == 0) { f = 0; break; } } return (f && (n != 1)); } int* proverca(int* A, int size){ int i,j,*B; int k=0; for (i=0; i<size; i++){ if ( prostae_chislo(A[i]) == 1); k++; } B=new int [k]; j=-1; for (i=0; i<size; i++) if (prostae_chislo(A[i]) == 0) B[j++]=A[i]; for(int j = 0; j < k; j++) cout << B[j] << " "; delete [] A; return B; } int main() { setlocale(LC_ALL, "rus"); int size; cout << "ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΡΠ°Π·ΠΌΠ΅Ρ ΠΌΠ°ΡΡΠΈΠ²Π°: "; cin >> size; int* A = new int[size]; cout << "ΠΠ°ΠΏΠΎΠ»Π½ΠΈΡΠ΅ ΠΌΠ°ΡΡΠΈΠ²: "; for(int i = 0; i<size; i++) cin >> A[i]; int* res = proverca(A, size); cout <<" "<< res << endl; delete []A; return 0; }