Thursday, 14 December 2017

shell script to check the entered number is prime or not

Write a shell script to check the entered number is prime or not



Program:


echo Enter the Number
read a
b=2 c=0 d=1
while [ $b -lt $a ]
do
if [ `expr $a % $b` = 0 ]
then
c=`expr $c + $d`
fi
b=`expr $b + $d`
done
if [ $c != 0 ]
then
echo Not Prime Number
else
echo Prime Number
fi


OUTPUT:



No comments:

Post a Comment