当前位置:网站首页>打印出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>
边栏推荐
- [C language series] - three methods to simulate the implementation of strlen library functions
- Wapiti是什么以及使用教程
- Database operation day 6
- [electronic circuit] how to select ADC chip
- Day 5
- Win10 搭建MSYS2环境
- Summary of the first week
- ·Let's introduce ourselves to the way of programming·
- Relationship between link and @import
- SQL修复重复数据
猜你喜欢
随机推荐
Day 1
Basic use of redis
Laravel Swagger添加访问密码
Abstract classes and interfaces
DAY15(DAY16拓展):文件包含漏洞
Realize simple database query (incomplete)
Hcia-r & s self use notes (27) comprehensive experiment
What is sqlmap and how to use it
Sqlmap是什么以及使用方法
B - identify floating point constant problems
js简单代码判断打开页面的设备是电脑PC端或手机H5端或微信端
Three handshakes and four waves for the interview summary
Niuke network programming problem - [wy22 Fibonacci series] and [replace spaces] detailed explanation
·Let's introduce ourselves to the way of programming·
使用Qss设置窗体样式
dcat 批量操作弹窗及参数传递
Clickhouse learning (IV) SQL operation
shell基本操作(上)
QT setting background image method
【TypeScript】TypeScript中类型缩小(含类型保护)与类型谓词









