Deepak and primes


this code doesnt pass any testcases


try this

Can you please explain whats going on in this part of the code
image

in the prime sieve function we have made a p[] array which comprises of 1’s and 0’s
so 0 denotes that ith value is not prime whereas 1 denotes the ith value is prime

here we made a primes[] array which will store the value of prime number like 2,3,5,7…
so , for example to get the 3rd prime we can directly lookup in the primes array we have created

feel free to ask again

the dynamic memory allocation solved the segmentation error here.
that is what i think was the crux of the problem

How did you figure out that the dynamic memory allocations was required here??
because in the lecture videos sir didnt use a dynamic array

segmentation fault occurs when a wrong address is used or due to less memory available
so we can use heap memory

you should search about segmentation fault on google

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.