➤ If-else Statement in C
➤ Programs on if-else
➤ Switch Case in C
➤ Switch case Programs
➤ Conditional Operator
➤ While loop in C
➤ Do-while loop in C
➤ While vs do-while
➤ For loop in C
➤ Break keyword in C
➤ Continue keyword in C
➤ Break vs Exit in C
➤ Goto keyword in C
☕️ Flow Control Programs
➤ Largest in 3 Numbers
➤ Find Grade of student
➤ Find the absolute value
➤ Vowel or Consonant
➤ Leap Year Program
➤ Simple calculator in C
➤ Check Odd or Even
➤ Roots of Quadratic Equation
➤ Find Reverse of Number
➤ Factors of a number in C
➤ Generate Multiplication table
➤ Find Power of a Number
➤ Find GCD and LCM
➤ Find factorial of Number
➤ Count Number of Digits
➤ Sum of digits in Number
➤ Sum of N Natural Numbers
➤ Sum of Squares of Natural No.
➤ Find Sum of Odd Numbers
➤ Find the Sum of Series
➤ Find Fibonacci series in C
➤ Sum of the Fibonacci series
➤ Sum until enters +ve numbers
➤ Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
➤ Celsius to Fahrenheit
➤ Fahrenheit to Celsius
➤ Decimal ↔ Binary
➤ Decimal ↔ Octal
➤ Octal ↔ Binary in C
☕️ Number Programs in C
➤ Prime Number in C
➤ Strong Number in C
➤ Krishnamurthy Number
➤ Neon Number in C
➤ Palindrome number
➤ Perfect Number in C
➤ Armstrong Number
☕️ Pattern Programs in C
➤ Pattern programs in C
➤ Printing pattern using loops
➤ Floyd’s triangle Program
➤ Pascal Triangle Program
➤ Pyramid Star Pattern in C
➤ Diamond Pattern Programs
➤ Half Diamond pattern in C
➤ Print Diamond Pattern
➤ Hollow Diamond Pattern
➤ Diamond Pattern of Numbers
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
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 do you find anything incorrect? Let us know in the comments. Thank you!