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.
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.