+ 3
At some point n%i==0, so it follows that IsPrime gets set to 0. Now if you don't reset IsPrime=1, then the outer loop continues with IsPrime=0 forever after, and NoOfPrimes++ never executes. This means thereafter the while condition never changes.
23rd Jun 2022, 8:56 AM
Brian
Brian - avatar