2.4K
In this tutorial, you’ll learn what is a Neon number and also create Shell Script to Check Neon Number.
What is Neon Number?
A neon number is a number where the sum of digits of the square of the number is equal to the number.
For example if the input number is 9, its square is 9*9 = 81 and sum of the digits is 9. i.e. 9 is a neon number.
Shell Script to Check Neon Number
#!/bin/sh
read -p "Enter the number: " num
square=$(( num * num ))
sum=0
while [ $square -gt 0 ]
do
lastdigit=$(( square % 10 ))
sum=$(( sum + lastdigit ))
square=$(( square / 10 ))
done
if [ $sum -eq $num ]
then
echo "$num is a neon number"
else
echo "$num is not a neon number"
fi
Output
anupmaurya@linux:~$ ./neon.sh
Enter the number: 9
9 is a neon number
anupmaurya@linux:~$