Neon Number

16 Mar, 2022
A neon number is a number where the sum of digits of 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++
Java
Python
C#
PHP
Javascript
// 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 Codeint main(void){    // Printing Neon Numbers upto 10000    for (int i = 1; i <= 10000; i++)        if (checkNeon(i))            cout << i << " ";   }
// Java program to check and print// Neon Numbers upto 10000import java.io.*; class GFG {    // function to check Neon Number    static boolean 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    public static void main(String args[])                        throws IOException    {        // Printing Neon Numbers upto 10000        for (int i = 1; i <= 10000; i++)            if (checkNeon(i))                System.out.print(i + " ");           }}// This code is contributed by Nikita Tiwari.
# Python program to check and print# Neon Numbers upto 10000 # function to check Neon Numberdef checkNeon (x) :    # storing the square of x    sq = x * x         # calculating the sum of digits    # of sq    sum_digits = 0    while (sq != 0) :        sum_digits = sum_digits + sq % 10        sq = sq / 10         return (sum_digits == x) # Driver Code i = 1# Printing Neon Numbers upto 10000while i <= 10000 :    if (checkNeon(i)) :        print i,    i = i + 1 # This code is contributed by Nikita Tiwari.
// C# program to check and print// Neon Numbers upto 10000using System; class GFG{    // function to check Neon Number    static bool 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    public static void Main()                             {        // Printing Neon Numbers upto 10000        for (int i = 1; i <= 10000; i++)            if (checkNeon(i))                Console.Write(i + " ");    }} // This code is contributed by vt_m.
<?php// PHP program to check and print// Neon Numbers upto 10000 function checkNeon($x){         // storing the square of x    $sq = $x * $x;     // calculating the     // sum of digits of sq    $sum_digits = 0;    while ($sq != 0)    {        $sum_digits = $sum_digits +                         $sq % 10;        $sq = $sq / 10;    }    return ($sum_digits == $x);}     // Driver Code    // Printing Neon Numbers    // upto 10000    for ($i = 1; $i <= 10000; $i++)        if (checkNeon($i))            echo $i . " ";             // This code is contributed by Sam007?>
<script> // Javascript program to check and print// Neon Numbers upto 10000     // function to check Neon Number    function checkNeon(x)    {        // storing the square of x        let sq = x * x;         // calculating the sum of digits        // of sq        let sum_digits = 0;        while (sq != 0) {            sum_digits = sum_digits + sq % 10;            sq = Math.floor(sq / 10);        }        return (sum_digits == x);    } // driver program        // Printing Neon Numbers upto 10000        for (let i = 1; i <= 10000; i++)            if (checkNeon(i))                document.write(i + " ");         </script>
Output:  
1 9
 
Neon Number | GeeksforGeeks - YouTubeGeeksforGeeks530K subscribersNeon Number | GeeksforGeeksWatch laterShareCopy linkInfoShoppingTap to unmuteIf playback doesn't begin shortly, try restarting your device.You're signed outVideos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.CancelConfirmMore videosMore videosSwitch cameraShareInclude playlistAn error occurred while retrieving sharing information. Please try again later.Watch on0:000:000:00 / 3:18•Live•<div class="player-unavailable"><h1 class="message">An error occurred.</h1><div class="submessage"><a href="https://www.youtube.com/watch?v=g2Kp_2xPVHY" target="_blank">Try watching this video on www.youtube.com</a>, or enable JavaScript if it is disabled in your browser.</div></div>
This article is contributed by Nikita Tiwari. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. 
Sam007
sanjoy_62
arorakashish0911
simmytarika5
series
Mathematical
Mathematical
series
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Algorithm to solve Rubik's Cube
Merge two sorted arrays with O(1) extra space
Program to print prime numbers from 1 to N.
Find next greater number with same set of digits
Segment Tree | Set 1 (Sum of given range)
Check if a number is Palindrome
Count ways to reach the n'th stair
Count all possible paths from top left to bottom right of a mXn matrix
Fizz Buzz Implementation
Product of Array except itself