简体   繁体   中英

I'm trying this question but unable to solve this. Anyone please help me with this

Write a program in javascript to find the count of prime numbers in a series from 2 to n. [2, n]

Input Format: A single integer (n). 2 <= n <= 100. A single integer (n). 2 <= n <= 100.

program:

function primeCount(input) {
    let primeCount;
  
    
  
    return primeCount;
}
function isPrimeNumber(num) {
 for ( let i = 2; i < num; i++ ) {
     if ( num % i === 0 ) {
         return false;
     }
 }
  return true;
 }

function displayValue(n) {
   var arr = [2];
   for ( let i = 3; i < n; i+=2 ) {
     if ( isPrimeNumber(i) ) {
        arr.push(i);
     }
  }
  console.log(arr); // use arr result on your own
 }

 displayValue(100);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM