不用函数,怎样求出200以内所有的质数

不用函数,怎样求出200以内所有的质数。
因为上课还没讲道函数,但是课后作业有这个题

繁花不似锦
浏览 797回答 1
1回答

开心每一天1111

var sum=0;&nbsp; &nbsp; for(var i=2;i<200;i++){&nbsp; &nbsp; &nbsp; &nbsp; var count=0;&nbsp; &nbsp; &nbsp; &nbsp; for(var j=2;j<i;j++){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(i%j==0){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; count++;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; if(count==0){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(i);//质数&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum++;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; console.log(sum);//总数
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript