shell编程判断100以内所有素数(质数)

echo -n "please enter number:"
read n
declare -I a 
for((i=1;i<=n;i++))
do 
   for((x=1;x<=i;x++))
   do 
   b=$(( $i%$x ))
   if [[ $b -eq 0 ]]; then
        a=$a+1
   fi
   done
   if [[ $a -eq 2 ]]; then
        echo -n $i " "
   fi
   a=0
done
echo

素数(质数):只能被1和其本身整除的整数

猜你喜欢

转载自blog.csdn.net/qq_36480179/article/details/82423857