当前位置:网站首页>JS output all prime numbers between 1-100 and calculate the total number

JS output all prime numbers between 1-100 and calculate the total number

2022-06-27 07:35:00 I am the sun?

The code is as follows :

<!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 + "&nbsp;&nbsp;&nbsp;&nbsp;");
					sum++;
			}
		}
		document.write("<br /> Primes in all :" + sum +  "  individual .");
	</script>
</head>
<body>
	
</body>
</html>

The operation results are as follows :
 Insert picture description here

原网站

版权声明
本文为[I am the sun?]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270720099474.html