Code In Tech - The Ultimate World of Computer Technology

Saturday, 12 May 2012

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

SOURCE CODE:

echo  “Enter the no.:”
read n
i=1
k=0
while [ $i –lt $n ]
do
     j =`expr $n % $i`
     if [ $j = 0 ]
     then
           k =`expr $k + $i`
     fi
     i =`expr $i + 1`
done
if [ $k = $n ]
then
     echo “Given no. is Perfect”
else
     echo “Given no. is not Perfect”
fi

OUTPUT

Enter the no.:
6
Given no. is Perfect

No comments :

Post a Comment