why my code is giving segmentation fault
Subset of 2,3,5
Your primes array size is 3
When you dry run your code, value of k in line 27 becomes greater than 2. So this is the reason of segmentation fault
but max value of key is 7 i.e …000111 in binary so max it will go to 2 as i initialize k with 0 for every key
Segmentation fault is mainly because your code is trying to access an out of bound index
Try and dry run your code. You will get to know about the error.
ok can you tell how can we store all subset of 2,3,5
It can be done by using simple recursion.
Each element has two options - It can be included in our subset or not.
Try to code it and tell me if you are able to do so. Otherwise I will help you.
I modified your code a bit. Please check it.
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.