Rather strange algorithms in use.
First generate 50000 random numbers between 2 and 10 inclusive.
Count how many of them are odd (on average, it will be 4/9 * 50000).
Allocate two arrays of size roughly 22222.
For each of those 22,000ish elements, if the corresponding element in the first array is either odd, or equal to 2, copy the value, otherwise leave the element unchanged.
Copy the second array to the third.
Print out the contents of the third array.
By the way, variable length arrays are not a standard feature in C++. Array a[] is the only one correctly allocated and freed.
You might better use std::vector for all of the arrays.
instead of
use
There is also an out of range access because the loop
|
for (int i =0;i<=primes;i++)
|
repeated one time too many.
The garbage values are simply those where nothing was copied to the primes array.