Skip to main content

Neon Number | C programming

 Q.8  WAP in C/ C++/ java to check whether the number is a Neon number or not.

Input: 9

Output: Neon Number

Explanation: the square is 9*9 = 81 and the sum of the digits of the square ( 8+1) is 9.


Solution : 

#include<stdio.h>

int sumofdigits(int x) // function to compute sum of digits
{
    int sum=0;
    while(x>0)
    {
        sum+=x%10;
        x=x/10;
    }
    return sum;
}

int main()
{
    int n;   
    printf("\nEnter any positive number : ");
    scanf("%d"&n);

    if (n<0)
    {
        printf("\nInvalid input! Enter the value again -->");
        main(); // calls the main() function again
    }
    else
    {
        if(n== sumofdigits(n*n))
        printf("%d is a Neon Number\n"n);
        else
        printf("%d Not a Neon Number.\n"n);
    }
    return 0;
// end of main()

Comments