Q:

C program to find a neon number

belongs to collection: C Programming on Numbers

0

A neon number is a number where the sum of digits of square of the number is equal to the number. For example, if the input number is 9, its square is 9*9 = 81 and the sum of the digits is 9. i.e. 9 is a neon.

In this program, you are going to learn that how to check a given number is neon or not.

Steps to check a given number is neon or not

1. Calculate the square of the given number.

2. Add each digit of the calculated square number.

3. compare the sum of digits of square of the number and number.

4. If the sum of digits equal to the number, then it is a neon otherwise it is not neon.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
int isNeon(int num)
{
    //storing the square of x
    int square = 0;
    //Store sum of digits (square number)
    int sum_digits = 0;
    //Calculate square of given number
    square = (num * num);
    while (square != 0)
    {
        sum_digits = (sum_digits + (square % 10));
        square = (square / 10);
    }
    return (sum_digits == num);
}
int main()
{
    int data = 0;
    int isNeonNumber = 0;
    //Ask to enter the number
    printf("Enter the number = ");
    scanf("%d",&data);
    // if is isNeonNumber is 1, then neon number
    isNeonNumber = isNeon(data);
    (isNeonNumber)? printf("neon number\n\n"):printf("Not a neon number\n\n");
    return 0;
}

 

Output:

Enter the number = 9

neon number

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Programming on Numbers

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
write a program to check and print neon numbers i... >>
<< Optimize way to find an nth Fibonacci number using...