I tried the code ,but getting segmentation fault …
Getting error in the code
In line number 10 before running for loop of j first check if p[i]==1 or not, if it’s 1 then only run for loop for j.
As I can see only these mistakes, if it still gives an error do let me know .
i have checked p[i]==1
but showing the error
Hey @siddhant_samal see this code for reference https://ide.codingblocks.com/s/301655
Have added few comments for better understanding 
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.