Problem: Write a C program to check whether the number is Neon or not.
A number is called a Neon Number if the sum of digits of the square of the number is equal to the original number.
Steps to check neon number in C:
- Input a number.
- Calculate the square of the number.
- Sum digits of the square.
- Check whether the calculated sum is equal to the original number.
- If yes then the number is Neon, else it is not.
Here is the implementation of the steps in C:
int num, digit, sum =0;
//Input a number
printf("Enter a number to check for neon number: \n");
//Calculate square of the input
int square = num*num;
//Sum the digits of the square
digit = square%10;
sum += digit;
square = square/10;
//Check if sum is equal to the input number
if(sum == num)
printf("Neon Number \n");
printf("Not a Neon Number \n");
Output:Enter a number to check for neon number:
To sum up the digits of the square, we have individually extracted each digit using the Modulus operator (i.e.
square%10) and added it to the
In the end, we compared the calculated
sum with the input number
num to check whether the given number is a Neon number or not.