In this tutorial, we will write a neon number program in Cpp. We will write two different programs.
- Check for neon number
- Display the neon number within the range
Neon Numbers
A number is said to be a neon number if the sum of the digits of a square of the number is equal t the original number.
Example: 9 is a Neon number (see explanation in the diagram).

Neon Number in C++
C++ Program to check for neon numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | //Cpp Program to check whether a given number is a Neon number or not #include <iostream> using namespace std; int main() { int num; cout << "Enter the number: "; cin >> num; int square = num * num; int sum = 0; while (square > 0) { int lastDigit = square % 10; sum = sum + lastDigit; square = square / 10; } if (sum == num) cout << num << " is a Neon number"; else cout << num << " is NOT a Neon number"; return 0; } |
Output:
Enter the number: 9
9 is a Neon number
C++ program to display all the neon number within a given range
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | //Cpp Program to check whether a given number is a Neon number or not #include <iostream> using namespace std; int checkForNeon(int x) { int square = x * x; int sumOfDigits = 0; while (square != 0) { sumOfDigits = sumOfDigits + square % 10; square /= 10; } return (sumOfDigits == x); } // Main function int main(void) { int lowestNum, highestNum; cout << "ENTER THE STARTING AND FINAL NUMBER FOR THE RANGE TO CHECK\n"; cout << "\nEnter the lowest number: "; cin >> lowestNum; cout << "Enter the Highest number: "; cin >> highestNum; cout << "\nNeon Number between them are:"; for (int i = lowestNum; i <= highestNum; i++) { if (checkForNeon(i)) cout << i << " "; } } |
Output:
ENTER THE STARTING AND FINAL NUMBER FOR THE RANGE TO CHECK
Enter the lowest number: 1
Enter the Highest number: 2000
Neon Number between them are:1 9