write a shell script to check the given number is armstrong or not
clear
echo enter any number to check armstrong or not
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 given number is armstrong
else
echo the given number is not armstrong
fi
output
clear
echo enter any number to check armstrong or not
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 given number is armstrong
else
echo the given number is not armstrong
fi
output
No comments:
Post a Comment