NEON NUMBER PROGRAM IN C
In this example , you will learn a program to check whether entered number is Neon number or not.
Neon Number:
Neon number is the number whose sum of digits of square of number is equal to the number itself.
Lets consider one example,
suppose we want to check whether 9 is neon number or not.
9² = 81
and sum of digits of 81 = 8+1 = 9
i.e. the number itself.
Thus, 9 is a neon number.
Program:
//Program to check whether given number is Neon number or not
#include <stdio.h>
int main( )
{
int num, rem, sq, sum=0;
printf("Enter any number:");
scanf("%d",&num);
sq=num*num;
while(sq !=0)
{
rem= sq%10;
sum=sum +rem;
num=num/10;
}
if(sum==num)
{
printf("%d is a neon number",num);
}
else
{
printf("%d is not a neon number",num);
}
return 0;
}
#include <stdio.h>
int main( )
{
int num, rem, sq, sum=0;
printf("Enter any number:");
scanf("%d",&num);
sq=num*num;
while(sq !=0)
{
rem= sq%10;
sum=sum +rem;
num=num/10;
}
if(sum==num)
{
printf("%d is a neon number",num);
}
else
{
printf("%d is not a neon number",num);
}
return 0;
}
Output:
Enter the number: 9
9 is Neon number
Enter the number:85
85 is not a Neon number
9 is Neon number
Enter the number:85
85 is not a Neon number
So that's it ! Just try this code by your own. If you have any doubts then feel free to drop a comment . I'll be happy to answer your questions .
Keep coding....
Comments
Post a Comment