javascript - How to find all prime numbers within 200 without using functions
巴扎黑
巴扎黑 2017-05-19 10:29:40
0
3
866

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

巴扎黑
巴扎黑

reply all(3)
PHPzhong

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);//总数
世界只因有你

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

淡淡烟草味
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;
        }
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template