Pass some elements of array to other
I have an array containing multiple numbers, now I have to extract only prime numbers and save them in other array...can anyone tell how to pass prime numbers in other array? #include <iostream> using namespace std; bool isprime(int vs) { if (vs < 2) { return false; } for (int d = 2; ; d++) { if (vs % d == 0) { return false; } else { return true; } } } int main() { const int capacity = 10; int arr[capacity]; int prime[capacity]; cout << "enter array:\n"; for (int i = 0; i < capacity; i++) { int counter = 0; cin >> arr[i]; if (isprime(arr[i])) { prime[counter] = arr[i]; cout << arr[i] << " is prime" << endl; counter++; } } for (int counter = 0; counter < capacity; counter++) { cout << prime[counter] << endl; } }