0
I want to count the number of prime number from 1 upto the input number. Can't figure out what's wrong with my code.
6 odpowiedzi
+ 4
Your logic is wrong, the count will be updated every time when the resultant value of "if" becomes 0.
See if this helps-
Edit: made some changes for readability.
https://code.sololearn.com/ce17hp0J4z5o/?ref=app
+ 4
Remove first line from your Code and Check again.
+ 2
Sayeef A prime number can only be divisible by 1 and the number itself so only when count becomes 2 it is possible.
Do you get it now?
+ 1
Yes, thank you Avinesh
0
Avinesh I know it's right but can't seem to wrap my head around how count==2 makes it logical for primes to increase by 1