📌  相关文章
📜  如何在 shell 脚本中检查素数 - Shell-Bash 代码示例

📅  最后修改于: 2022-03-11 14:49:43.881000             🧑  作者: Mango

代码示例1
#!/bin/bash
echo -e "Enter Number : \c"
read n
for((i=2; i<=$n/2; i++))
do
  ans=$(( n%i ))
  if [ $ans -eq 0 ]
  then
    echo "$n is not a prime number."
    exit 0
  fi
done
echo "$n is a prime number."