JavaScript打印素数

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>素数</title>
</head>

<body>
	<script language="javascript">
	function isPrime(n){
		for(var i=2;i<=Math.sqrt(n);i++){
			if(n%i==0)
				return false
			return true
		}
	}
var n=prompt("input a number:","");
		if(isPrime(n)){
		   document.write("the number is a prime");
		   }
		else
			document.write("the number is not a prime");
	</script>
</body>
</html>

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页