当前位置:网站首页>打印出1-100之间的所有质数
打印出1-100之间的所有质数
2022-07-29 05:19:00 【学习记录而已】
打印出1-100之间的所有质数
1、找到1-100之间所有的数
2、判断是否为质数
3、打印出找到的质数
<script type="text/javascript">
/**
* 2、打印出1-100之间的所有质数
* (质数:除了1和他自身外,不能被其他数整除的数叫做质数)
* 我们知道1既不是质数也不是合数,所以下面的代码直接从2开始
*/
//打印2-100之间所有的数
for(var i=2;i<=100;i++){
var flag=true;
//判断i是否是质数,获取2-i之间的所有数
for(var j=2;j<i;j++){
//判断i是否能被j整除
if(i%j == 0){
//如果进入判断则证明i不是质数,修改flag的值为false
flag=false;
}
}
if(flag){
document.write(i+" ");
}
}
</script>
边栏推荐
- ClickHouse学习(一)ClickHouse?
- Basic use of redis
- Hcia-r & s self use notes (27) comprehensive experiment
- Related knowledge of elastic box
- Summary of knowledge points related to forms and forms
- DAY4:SQL Sever 简单使用
- 表格与表单相关知识点总结
- Common characteristic engineering operations
- Relative positioning and absolute positioning
- Clickhouse learning (VII) table query optimization
猜你喜欢

Clickhouse learning (IV) SQL operation

On Paradigm

Win10 搭建MSYS2环境

DAY15:文件包含漏洞靶场手册(自用 file-include 靶场)
![[C language series] - a recursive topic](/img/a2/9d65728e672ab16c4fc0d427c241c4.png)
[C language series] - a recursive topic

What is wapiti and how to use it

微信小程序-组件传参,状态管理

Merge the same items in the same column in table

Clickhouse learning (IX) Clickhouse integrating MySQL

用threejs 技术做游戏跑酷
随机推荐
第三课threejs全景预览房间案例
Qt布局管理--部件拉伸(Stretch)原理及大小策略(sizePolicy)
HCIA-R&S自用笔记(24)ACL
Realize simple database query (incomplete)
Niuke network programming problem - [wy22 Fibonacci series] and [replace spaces] detailed explanation
Clickhouse learning (IX) Clickhouse integrating MySQL
Build msys2 environment with win10
Wechat applet - component parameter transmission, state management
PHP如何生成二维码?
php写一个购买全网最低价的纸尿裤
DAY15(DAY16拓展):文件包含漏洞
Basic use of redis
What is sqlmap and how to use it
Related knowledge of elastic box
Hcia-r & s self use notes (26) PPP
相对定位和绝对定位
uniapp组件之倒计时(如阅读协议倒计时、完成学习倒计时)
组件传参与生命周期
Wechat applet change attribute value -setdata- bidirectional binding -model
[electronic circuit] how to select ADC chip