> I can't get it to work with numbers >=12; it gives a system error that it failed unexpectedly.
1. You don't free the memory you allocate. Eventually, you'll run out of memory.
2. You run off the end of the memory allocated.
for ( int i = 2 ; i <= n ; i++ )
If you want <= n, then you need to allocate n+1 items.
It was always wrong, you just got caught with your hand in the cookie jar at n >= 12.
3. Unlike Ptolemy's answer, your array serves no purpose.