Answers for "how to check prime number in shell script"

0

how to check prime number in shell script

#!/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."
Posted by: Guest on May-03-2021

Code answers related to "how to check prime number in shell script"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language