Showing posts with label srmstrong number. Show all posts
Showing posts with label srmstrong number. Show all posts

Monday, 9 July 2012

Write a shell script to check whether a given number is an Armstrong number or not.


echo "Enter a number: "
read c

x=$c
sum=0
r=0
n=0
while [ $x -gt 0 ]
do
r=`expr $x % 10`
n=`expr $r \* $r \* $r`
sum=`expr $sum + $n`
x=`expr $x / 10`
done

if [ $sum -eq $c ]
then
echo "It is an Armstrong Number."
else
echo "It is not an Armstrong Number."
fi

--------------------------------------------------------------------------------------------------------------
                OUTPUT
Enter a number:
153
It is an Armstrong Number.