当前位置:网站首页>打印出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>
边栏推荐
- Wechat applet change attribute value -setdata- bidirectional binding -model
- Wechat applet - component parameter transmission, state management
- Relative positioning and absolute positioning
- 如何 Pr 一个开源composer项目
- Selection options of uniapp components (such as package selection)
- Qt设置背景图片方法
- 个人学习笔记
- Clickhouse learning (XI) clickhouseapi operation
- ClickHouse学习(一)ClickHouse?
- 第五空间智能安全⼤赛真题----------PNG图⽚转换器
猜你喜欢

DAY6:利用 PHP 编写文件上传页面

【TypeScript】深入学习TypeScript对象类型

DAY15(DAY16拓展):文件包含漏洞

Qframe class learning notes

Playwright实战案例之爬取js加密数据
![[C language series] - storage of deep anatomical data in memory (I) opening of summer vacation](/img/a8/367ff90ad1b65c404de446d198365b.png)
[C language series] - storage of deep anatomical data in memory (I) opening of summer vacation
![[JS question solution] questions 1-10 in JS of niuke.com](/img/9d/4bae4a9a048e4e5412f157ec632c94.png)
[JS question solution] questions 1-10 in JS of niuke.com
![[C language series] - three methods to simulate the implementation of strlen library functions](/img/b2/00cd2b79adc23813088656ec3bc17e.png)
[C language series] - three methods to simulate the implementation of strlen library functions

Longest string without duplicate characters

Installation steps and environment configuration of vs Code
随机推荐
365 day challenge leetcode1000 question - day 036 binary tree pruning + subarray and sorted interval sum + delete the shortest subarray to order the remaining arrays
微信小程序更改属性值-setData-双向绑定-model
QT layout management -- Part stretch principle and sizepolicy
Summary of the first week
[C language series] - string + partial escape character explanation + annotation tips
[C language series] - detailed explanation of file operation (Part 1)
表格与表单相关知识点总结
Installation steps and environment configuration of vs Code
[electronic circuit] how to select ADC chip
重绘与回流的关系
TXT 纯文本操作
uniapp组件之倒计时(如阅读协议倒计时、完成学习倒计时)
Day14: upload labs customs clearance tutorial
DAY4:MySQL 数据库的建立及简单实用
DAY15:文件包含漏洞靶场手册(自用 file-include 靶场)
Wapiti是什么以及使用教程
[untitled]
shell基本操作(下)
基础爬虫实战案例之获取游戏商品数据
Basic use of redis