var num = prompt('请输入一个数字');
function zs(num) {
var arr = [];
for (var i = 0; i <= parseInt(Math.sqrt(num)); i++) {
arr[arr.length] = i;
}
var arr1 = [];
for (let i = 2; i <= arr.length - 1; i++) {
if (num % arr[i] == 0) {
arr1.push(0);
}
}
if (arr1[0] == 0) {
return '这不是质数'
} else {
return '这是质数'
}
}
alert(zs(num));
网友评论