You set array[i]
to i
if i
is a prime number. But you do not set array[i]
to any value if i
is not a prime number. You probably only want to store the prime numbers in array
, so
void fillArray(int array[], const int N){
for (int i = 2, j = 0; j < N; ++i){
if (primenumber(i))
array[j++] = i;
}
}
2
solved Filling arrays with prime numbers [closed]