Why it is giving segmentation fault?

@mayank10 in your sieve function look at inner for loop of your nested for loops, terminating condition is wrong, correct it and code will work fine.