echo "Enter
a number "
read n
s=0
num=$n
r=0
while [ $n -gt 9 ]
do
s=0
while [ $n -gt 0 ]
do
r=` expr $n \% 10 `
s=` expr $s \+ $r `
n=` expr $n \/ 10 `
done
echo "$s"
n=$s
done
if [ $n -eq 1 ]
then
echo "Magic Number"
else
echo "Not a Magic Number"
fi
read n
s=0
num=$n
r=0
while [ $n -gt 9 ]
do
s=0
while [ $n -gt 0 ]
do
r=` expr $n \% 10 `
s=` expr $s \+ $r `
n=` expr $n \/ 10 `
done
echo "$s"
n=$s
done
if [ $n -eq 1 ]
then
echo "Magic Number"
else
echo "Not a Magic Number"
fi
Comments