echo "Enter a number: "
read num
i=2
f=0
while [ $i -le `expr $num / 2` ]
do
if [ `expr $num % $i` -eq 0 ]
then
f=1
fi
i=`expr $i + 1`
done
if [ $f -eq 1 ]
then
echo "The number is composite"
else
echo "The number is Prime"
fi
--------------------------------------------------------------------------------------------------------------
OUTPUT
Enter a number:
5
The number is Prime
read num
i=2
f=0
while [ $i -le `expr $num / 2` ]
do
if [ `expr $num % $i` -eq 0 ]
then
f=1
fi
i=`expr $i + 1`
done
if [ $f -eq 1 ]
then
echo "The number is composite"
else
echo "The number is Prime"
fi
--------------------------------------------------------------------------------------------------------------
OUTPUT
Enter a number:
5
The number is Prime
9 comments:
This doesn't hold good for num=9
perfect
Easiest Program to Find Whether Given Number Is Prime Number Or Not
Thank you so much helping.
I was preparing for my exam where I needed this program.
So many spam messages.
So many spam messages.
good
good
line 7: [: 2: unary operator expected
getting this error
Post a Comment