Calculate Armstrong Number Bash shell programming in Linux and UNIX shell programming

By through following shell programming you can find out the give number is Armstrong or not. Example 153 is a Armstrong number because 1*1*1+5*5*5+3*3*3=153. so it is satisfied the Armstrong condition. 153 numbers is the Armstrong number. We will done these operation using basic arithmetic operation in Linux and UNIX bash shell programming
Source code bash shell Programming Algorithm
echo "Enter the number"
read n
t=$n
s=0
b=0
c=10
while [ $n -gt $b ]
do
r=`expr $n % $c`
i=`expr $r \* $r \* $r`
s=`expr $s + $i`
n=`expr $n / $c`
done
echo $s
if [ $s -eq $t ]
then
echo "Amstrong number"
else
echo "Not an Armstrong number"
fi

OUTPUT CS1252 Operating Systems lap Calculate ARMSTRONG NUMBER
[redhat35@localhost Rhel5]$ sh amstrong.sh
Enter the number
213
36
Not an Armstrong number
[redhat35@localhost Rhel5]$ sh amstrong.sh
Enter the number
153
153
Armstrong number

Related post