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.

https://code.sololearn.com/c87C8hJhJqEi/?ref=app

27th Dec 2019, 3:27 PM
Sayeef
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
27th Dec 2019, 4:17 PM
Avinesh
Avinesh - avatar
+ 4
Remove first line from your Code and Check again.
27th Dec 2019, 3:59 PM
A͢J
A͢J - avatar
+ 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?
27th Dec 2019, 5:05 PM
Avinesh
Avinesh - avatar
+ 1
Yes, thank you Avinesh
27th Dec 2019, 5:37 PM
Sayeef
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
27th Dec 2019, 4:59 PM
Sayeef