Whats the mistake segmentation fault is coming please tell
it is giving segmentation fault because you are making array of size 10^7 inside function
to make such a large sized array you have to make array global
also in question you have to print nth prime numbere
but you are printing p[n]
p[n] this tell us about whether n is prime or not
so what you have to do is make a vector v and then print v[n]
look at Modified code below