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.

2 comments:

Reshma sm Alam said...

thank you so much ...!! :)
it's helpful

Sukanta Chakraborty said...

Thnx...realy its very help ful

Post a Comment