+ 2

Any body Can explain me how Prime number print I have a code and code printing prime number but didn't get the logic(javascript)

Tell me please https://code.sololearn.com/Whorxz86jinE/?ref=app Code

13th May 2021, 2:41 PM
Rohit Kumar
Rohit Kumar - avatar
2 ответов
+ 3
It is a very simple approach first loop is running from 2 to 20 now for each of this value we haave to check it is prime Or not Now we know that number is not prime if it is divisible by any number less than itself except 1 So second loop is running from 2 to that number and if any number divides that number then it is not prime so we set that to false and then outside loop we check if it's value is true then we print that number
13th May 2021, 2:48 PM
YUGRAJ
+ 1
Prime number is a number that has exactly 2 divisors. There is one common for all prime number, the 2 divisors are always 1 and itself. If N is prime, there shouldn't be any divisor between 2 to N-1. So the program loops in this range and if there is a divisor, notPrime will be true. Side note, 1 is not prime because it only has 1 divisor, which is 1.
13th May 2021, 2:51 PM
你知道規則,我也是
你知道規則,我也是 - avatar