C++ Program To Check And Print Neon Number in a Given Range Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report A neon number is a number where the sum of digits of the square of the number is equal to the number. The task is to check and print neon numbers in a range. Examples: Input: 9 Output: Neon Number Explanation: square is 9*9 = 81 and sum of the digits of the square is 9. Input: 12 Output: Not a Neon Number Explanation: square is 12*12 = 144 and sum of the digits of the square is 9 (1 + 4 + 4) which is not equal to 12. The implementation is simple, we first compute square of given number, the find sum of digits in the square. C++ // C++ program to check and print // Neon Numbers upto 10000 #include <iostream> using namespace std; #include <math.h> int checkNeon(int x) { // Storing the square of x int sq = x * x; // Calculating the sum of // digits of sq int sum_digits = 0; while (sq != 0) { sum_digits = sum_digits + sq % 10; sq = sq / 10; } return (sum_digits == x); } // Driver Code int main(void) { // Printing Neon Numbers upto 10000 for (int i = 1; i <= 10000; i++) if (checkNeon(i)) cout << i << " "; } Output: 1 9 Time Complexity: O(n*log10(n*n)) where n is the number till which neon numbers to be printed. Space Complexity: O(1) as no extra space has been used. Create Quiz Comment K kartik Follow 0 Improve K kartik Follow 0 Improve Article Tags : C++ Programs C++ C Basic Programs Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like