# C Program to Find Neon Number

We will write a C program to find Neon number. For loop or while loop can be used. After that, we will write another C program to find the neon number within a range. A Prerequisite example is a C program to find the sum of digits. First of all, we should know that, what is the Neon number?

## Neon Number

If the sum of digits of the square of the number is equal to the same number, then the number is called Neon number.

Example:- 9
Square of 9 = 92= 81
Sum of the digits of the square = 8+1= 9
So, 9 is a Neon number.

Another Example:- 1
Square of 1= 12= 1
Sum of the digits of the square = 1
S0, 1 is a Neon number.

Another Example :- 5
Square of 5 = 52 = 25
Sum of the digits of the square = 2+5 = 7
Here, 5 is not equal to 7.
So, 5 is not a Neon number.

## C Program to check Neon Number using While Loop

``````#include<stdio.h>
int main()
{

int n, sqr, rem, sum=0;

printf("Enter Number: ");
scanf("%d",&n);

sqr = n*n; //we can also use pow()

while(sqr!=0)
{
rem = sqr%10;
sum += rem; //sum = sum + rem
sqr /= 10;  //sqr = sqr / 10
}

if(sum==n)
printf("%d is a neon number.\n",n);
else
printf("%d is NOT a neon number.\n",n);

return 0;
}``````

Output:-

Enter Number: 1
1 is a neon number.

Enter Number: 5
5 is NOT a neon number.

The variables in this program are n, sqr, rem, and sum. The variable sum is initialized with 0, variable n, sqr, and rem will hold the value of the inputted number, the square of the number, and remainder respectively. First, we take a number as an input from the user, then calculate its square value, which will store in the variable sqr.

Using the while loop, we find every digit in the sqr and after finding every digit, the sum will be calculated. the sum is the value of the addition of every digit of sqr. While loop ends when sqr becomes 0. Now, using the if-else conditional statement we check that is the sum equal to the number inputted from the user? If yes then the number is a Neon number else number is not a Neon number.

## Using For Loop

``````#include<stdio.h>
int main()
{
int n, i, sqr, sum=0;

printf("Enter Number: ");
scanf("%d",&n);

sqr = n*n;

for(i=sqr;i>0;i/=10)
{
sum += (i % 10);
}

if(sum==n)
printf("%d is a neon number.\n",n);
else
printf("%d is NOT a neon number.\n",n);

return 0;
}``````

The same as the previous program, this program also finds that the number is neon number or not, nut using for loop. Logic is the same as while loop.

## C Program to Find Neon Number in a Given Range

``````#include<stdio.h>
int main()
{
int m, n, i, sqr, j, sum;

printf("Enter The Range m and n Value(m<n): ");
scanf("%d %d",&m,&n);

printf("Neon Number from %d to %d are:\n",m,n);

for(i=m;i<=n;i++)
{
sum = 0;
sqr = i*i;

for( j=sqr ;j>0 ;j/=10 )
{
sum += (j%10);
}

if(sum == i)
printf("%d\t",i);
}

return 0;
}``````

Output:-

Enter The Range m and n Value(m<n): 0,1000
Neon Number from 0 to 1000 are: 0 1 9

Here, we write a program to find the Neon number in a given range. The range starts from m and ends at n. 0, 1 and 9 are only known Neon number.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!