当前位置:网站首页>js输出1-100之间所有的质数并求总个数
js输出1-100之间所有的质数并求总个数
2022-06-27 07:20:00 【I am the sun?】
代码如下:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<script type="text/javascript">
var sum = 0;
for(var i = 1;i <= 100;i++){
var flag = true;
if(i == 1)
flag = false;
for(var j = 2;j < i;j++){
if(i % j == 0){
flag = false;
break;
}
}
if(flag){
document.write(i + " ");
sum++;
}
}
document.write("<br />质数一共有:" + sum + " 个。");
</script>
</head>
<body>
</body>
</html>
运行结果如下:
边栏推荐
猜你喜欢
随机推荐
apifox学习
How to write controller layer code gracefully?
File 与 MultipartFile概述
Construction of defense system for attack and defense exercises part II common strategies for responding to attacks
Winow10 installation nexus nexus-3.20.1-01
sql sever列名或所提供值的数目与表定义不匹配
请问网页按钮怎么绑定sql语句呀
JDBC transaction commit case
Stream常用操作以及原理探索
VNC Viewer方式的远程连接树莓派
一个人管理1000台服务器?这款自动化运维工具一定要掌握
一個人管理1000臺服務器?這款自動化運維工具一定要掌握
The first part of the construction of the defense system of attack and defense exercise is the introduction and the four stages of Defense
Sword finger offer 07 Rebuild binary tree
[compilation principles] review outline of compilation principles of Shandong University
win10远程连接云服务器
JDBC操作Mysql示例
Installation and functions of uview
多表联查--07--- Hash join
jupyter notebook文件目录








