Code In Tech - The Ultimate World of Computer Technology

Saturday 12 May 2012

Shell script to check whether the given no. is prime or not

SOURCE CODE:


echo “Enter the no.”
read n
i=2
while [ $i –lt $n ]
do
e=`expr $n % $i`
if test  $e –eq 0
then
     echo “Given no. is not PRIME”
     break;
else
     i=`expr $i + 1`
fi
done
if test $i –eq $n
then
     echo “Given no. is PRIME”
fi

OUTPUT:

Enter the no.
5
Given no. is PRIME
 

No comments :

Post a Comment