
Prime Number in Looping Using JavaScript
PRIME NUMBER: A number greater than 1 cannot be divided evenly by any number other than 1 and itself, it is called prime number. FIND A GIVEN NUMBER IS PRIME NUMBER OR NOT: LOGIC: ✓ If a number have only 2 count divisors is prime,On tha other hand a number have a more than 2 divisors not a prime number. EXAMPLE: ✓ NO 8.This number divide by 1,2,4,8 and gets reminder 0.So 8 have four divisors and not a prime number. ✓ NO 13.This number divide by 1 and 13 and gets reminder 0.so 13 have 2 divisors and prime number. PROGRAM: EXPLANATION: 1.First take count=0. 2.Then take number = 10. 3.Next take initial value i=1. 4.Then check the condition , number is 10, so take the value (i<=number). 5.Next check the if condition (number % i == 0). ◾ i is 1.(1<=number true).Then go next step. (number(10) % 1== 0 true).because the 10 is divided by 1 and the remaider is 0.Condition is true.Then, 6.Increment the value of count++. 7.Then increment the value of i++. ◾ i is 2.(2<=number true).(number(10) % 2=
Continue reading on Dev.to Tutorial
Opens in a new tab



