Answers for "find prime numbers in range javascript"

0

find prime numbers in range javascript

// take input from the user
const lowerNumber = 1
var higherNumber = 10000

console.log(`The prime numbers between ${lowerNumber} and ${higherNumber} are:`);

// looping from lowerNumber to higherNumber
for (let i = lowerNumber; i <= higherNumber; i++) {
    let flag = 0;

    // looping through 2 to user input number
    for (let j = 2; j < i; j++) {
        if (i % j == 0) {
            flag = 1;
            break;
        }
    }

    // if number greater than 1 and not divisible by other numbers
    if (i > 1 && flag == 0) {
        console.log(i);
    }
}
Posted by: Guest on April-07-2021

Code answers related to "find prime numbers in range javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language