Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

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."
 
PREVIOUS NEXT
Tagged: #check #prime #number #shell #script
ADD COMMENT
Topic
Name
8+8 =