Thursday, 19 December 2019

Bash program to check if the Number is a Prime or not


#===================================
# Tanzila Islam
# Email: tanzilamohita@gmail.com
#===================================

read num
f=0 # flag
for((i=2; i<=num/2; i++))
do
  f=1
  break
done
if [ $num == 1 ]
then
   echo "1 is neither prime nor composite."
elif [ $f == 0 ]
  then
    echo "$num is a prime number."
else
    echo "$num is not a prime number."
fi

No comments:

Post a Comment