search

Home  >  Q&A  >  body text

javascript - How to find all prime numbers within 200 without using functions

How to find all prime numbers within 200 without using functions.
Because I haven’t talked about functions in class yet, but there is this question in my homework

巴扎黑巴扎黑2747 days ago872

reply all(3)I'll reply

  • PHPz

    PHPz2017-05-19 10:31:40

    var sum=0;

        for(var i=2;i<200;i++){
            var count=0;
            for(var j=2;j<i;j++){
                if(i%j==0){
                    count++;
                }
            }
            if(count==0){
                console.log(i);//质数
                sum++;
            }
        }
        console.log(sum);//总数

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-19 10:31:40

    printf("%d", 2);
    printf("%d", 3);
    printf("%d", 5);
    ...

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-19 10:31:40

    for (let i = 1; i <= 200; i++) {
            let flag = 1;
            while (flag) {
                if (i % flag === 0 && flag !== 1 && flag !== i) {
                    flag = false;
                }
                if (flag === i) {
                    flag = false;
                    console.log(i)
                }
                flag = flag ? flag + 1 : false;
            }
        }
    

    reply
    0
  • Cancelreply