Sunday 15 January 2012

#program to check whether a entered number is prime or not


echo "Enter a number"
read a
b=1
c=0
while [ $b -le $a ]
do
if test `expr $a % $b` -eq 0
then
c=`expr $c + 1`
fi
b=`expr $b + 1`
done
if test $c -eq 2
then
echo "$a is a Prime number "
else
echo "$a is not a Prime number "
fi

No comments:

Post a Comment