0

# How can I decide that a number is prime number?

I have to ask for a number with "var n=prompt" and after that I have to determine that that number is prim or not. I have been learning cycles in Javascript and I didn't find any answer for that.

2 Antworten

+ 4

the most basic way is to iterate from one to that number continually dividing by that number.if there are no divisors,its a prime.
var is_prime=true
for(var i=2;i<num;i++)
if(num%i===0) is_prime=false;
console.log(is_prime);
this is very inefficient for large primes like 224346557567

0

Thank you for your help!
:)