Google Search

Wednesday, October 12, 2011

A SHELL SCRIPT PROGRAM ON PRIME NUMBER


 A SHELL SCRIPT PROGRAM ON PRIME NUMBER

echo ".....A SHELL SCRIPT PROGRAM ON PRIME NUMBER....."
echo "     INPUT     "
echo "---------------"
echo "Enter A Number :"
read n
b=1
c=0
while [ $b -le $n ]
do
x=`expr $n % $b`
if [ $x -eq 0 ]
then
          c=`expr $c + 1`
fi
b=`expr $b + 1`
done
echo "     OUTPUT     "
echo "---------------"
if [ $c -le 2 ]
then
echo "$n is Prime Number"
else
echo "$n is not Prime Number"
fi






[root@localhost root]# sh primeno.sh
.....A SHELL SCRIPT PROGRAM ON PRIME NUMBER.....
  INPUT
---------------
Enter A Number :
100
 OUTPUT
---------------
100 is not Prime Number
[root@localhost root]# sh primeno.sh
.....A SHELL SCRIPT PROGRAM ON PRIME NUMBER.....
  INPUT
---------------
Enter A Number :
7
 OUTPUT
---------------
7 is Prime Number

0 comments:

Post a Comment