Skip to main content

Program to find whether a number is magic or not in Linux/Unix

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

 

Comments

Popular posts from this blog

unix commands