Code In Tech - The Ultimate World of Computer Technology

Saturday, 12 May 2012

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

SOURCE CODE:

echo “ Enter the no.”
read n
l =`expr length $n`
i=1
d=1
while [ $i –le $l ]
do
     r=`expr $n | cut –c $i`
     i=`expr $i + 1`
     m=`expr $r \* $r \* $r`
     s=`expr $s + $m`
done
if [ $s = $n ]
then
     echo “The given no. is Armstrong.”
else
     echo “The given no is not Armstrong”
fi

OUTPUT:

Enter the no.
153
The given no. is Armstrong.

No comments :

Post a Comment