Please find my error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please find my error?

I wrote a code to find the next big prime number and print the distance between them. But it is only working till line 20. I don't understand what logic error or any other error is there preventing to print the output. Does anyone know? Please do tell me. https://code.sololearn.com/cxDr4U5OkU79/#c

1st Mar 2018, 2:55 PM
srihitha reddy
srihitha reddy - avatar
2 Answers
1st Mar 2018, 6:00 PM
John Wells
John Wells - avatar
0
I think that flag var MUST be initialized to 0 before the "prime checker loop" and not only if i is 2.... in mentioned loop you check if a number is a prime and set flag if it is not prime (set it to 1) but if it is, your flag i setted to last number (previous)and so on getting a infinite loop.... I repeat flag MUST setted to 0 before loop (for) and i think than you want do "i-n" in printing difference
1st Mar 2018, 5:32 PM
KrOW
KrOW - avatar