Home Linux Shell Script to Check Neon Number

Shell Script to Check Neon Number

by Anup Maurya
16 minutes read

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

read -p "Enter the number: " num
square=$(( num * num ))

while [ $square -gt 0 ]
  lastdigit=$(( square % 10 ))
  sum=$(( sum + lastdigit ))
  square=$(( square / 10 ))

if [ $sum -eq $num ]
 echo "$num is a neon number"
 echo "$num is not a neon number"


anupmaurya@linux:~$ ./neon.sh
Enter the number: 9
9 is a neon number

related posts

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.