Write a shell script to checkwhether a given no. is prime or not.

echo -e “Enter the number::\c”

read num

t=1

for (( i=2 ; i< expr $num-1 ; i++))

{

if [ expr $num % $i -eq 0 ]

then

t=0

fi

}

 

if [ $t -eq 0 ]

then

echo “Not Prime”

else

echo “Prime”

fi

 

OUTPUT::

 

Enter the number::5

Prime

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.