# Algorithm and flowchart to check whether a number is a Neon Number or not

[358 views]

### What are Neon numbers?

A number is said to be a Neon number if the sum of all the digits of the square of that number is equal to that number.
For example: Let us consider the number 9.
Square of the number: 9*9 = 81
Sum of digits of the square= 8 + 1 = 9
Therefore, 9 is a neon number.
Other examples include: 0, 1.
Let's consider the number 15.
Square of the number: 15*15 = 225
Sum of digits of the square= 2 + 2 + 5 = 9
But here, 15 ≠ 9.
Therefore, 15 is not a neon number.
Let us have a look at the algorithm and flowchart to check whether a given number is a Neon number or not.

### Algorithm for checking whether a number is a Neon Number:

Step 1. Start Step 2. Read the number from the user, say ‘n’ Step 3. Initialize the sum of the digits of the square, sum = 0 Step 4. Calculate the square of the number: 4.1: sq = n * n Step 5. Repeat WHILE sq != 0: 5.1: Extract the last digit by: d = sq % 10 5.2: Calculate sum by: sum = sum + d 5.3: Remove the last digit from the number: sq = sq / 10 Step 6. If n = sum: 6.1: Print “Neon number” Step 7. Else: 7.1: Print “Not Neon number” Step 8. Stop

### Explanation:

To check whether a number is Neon or not, we will have to first calculate the square of the number to be checked. In this algorithm, we have calculated the square using simple multiplication operation. After that, we will have to calculate the sum of the digits of the square.

In simple words, we will first find out the square and then extract each digit from the square of the number and calculate its sum.

The algorithm starts by taking the number, say ‘n’, to be checked as user input. We then initialize the sum of the digits of the square, ‘sum’ as zero; for easier calculation. The square of the number, ‘sq’, is calculated using the statement: sq = n * n. After this, we will start a while loop, which runs until sq is not equal to zero. We will then extract the last digit of the number by performing: d = sq % 10. After that the extracted digit is added to the sum of the digits, ‘sum’ with the help of the statement: sum = sum + d. This loop continues iterating until no digits are left in sq, that is, sq is equal to zero. Once we are out of the while loop, we will check whether the sum of the digits of the square and the original number are equal or not. If yes, the given number is Neon number, else it is not a Neon number.

Note: Here ‘%’ is the modulus operator which returns the remainder value after division.

### Flowchart to check if a number is a Neon Number or not: ## Getting any Errors while coding? Ask us on our new Forum: ##### Play 2048 Game Online and Relax. ##### Most Viewed Posts
Why does everyone hate Java?
How much JavaScript to learn for Web Development
How to Convert EPOCH to Date in Java