Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

prime numbers 1 to 100 in javascript

//Prime Number from 1 to 100
const arr = [] //Creating an Empty List for keeping all prime numbers
for(var p=2;p<=100;p++){ // 1 is not a prime number it is excluded and loop is started with 2 to 100.
  for(var i=2;i<p;i++ ){
            //2<2   ----->(Which is false program will return to last if)
    if(p%i == 0){ 													//|
      break															//|
    }																//|
  }																	//|
  if(p == i){   //Here and adds that number <-------------------------=
    arr.push(p)
  }
}
console.log(arr)
// Result :: [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #prime #numbers #javascript
ADD COMMENT
Topic
Name
4+6 =