Q:

write a program to check and print neon numbers in a given range

belongs to collection: C Programming on Numbers

0

write a  program to check and print neon numbers in a given range

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;
    int loop = 0;
    //Ask to enter the number
    printf("Enter the number upto you want check neon number = ");
    scanf("%d",&data);
    for (loop = 0; loop <= data; loop++)
    {
        // if is isNeonNumber is 1, then neon number
        isNeonNumber = isNeon(loop);
        if(isNeonNumber)
        {
            printf(" %d is neon number\n",loop);
        }
    }
    return 0;
}

Output:

Enter the number upto you want check neon number = 100000

 0 is neon number

 1 is neon number

 9 is 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
C program to print natural numbers from 1 to n... >>
<< C program to find a neon number...