Sunday, 17 June 2012

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


clear
echo enter any number..
read n
m=$n
sum=0
while [ $m != 0 ]
do
            y=`expr $m % 10`
            x=`expr $y \* $y \* $y`
            sum=`expr $sum + $x`
            m=`expr $m / 10`
done
if [ $sum -eq $n ]
then
            echo the number is armstrong...
else
            echo the number is not armstrong...
fi

No comments:

Post a Comment