C Program to Check Neon Number

C Program to Check Neon Number

C program to check neon number; Through this tutorial, we will learn how to check neon number in c program using for loop, while loop and function.

Let’s use the following algorithm to write a program to check whether a number is neon or not; as follows:

  • Take the number as input from the user
  • Find the square of the number
  • Find the sum of the digits in the square
  • Compare the sum with the number. If both are equal then it is a Neon number

Programs to Check Neon Number

  • C Program to Check Neon Number using For Loop
  • C Program to Check Neon Number using While Loop
  • C Program to Check Neon Number using Function

C Program to Check Neon Number using For Loop

#include <stdio.h>

int main()
{
    int i, num, square, sumDigits = 0;

    printf("Enter a number: ");
    scanf("%d", &num);

    square = num * num;

    for(i = 0; i<=square; i++)
    {
        sumDigits += square % 10;
        square /= 10;
    }

    if (num == sumDigits)
    {
        printf("It is a Neon number\n");
    }
    else
    {
        printf("It is not a Neon number\n");
    }

    return 0;
}

The output of the above c program; as follows:

Enter a number: 10
It is not a Neon number

C Program to Check Neon Number using While Loop

#include <stdio.h>

int main()
{
    int num, square, sumDigits = 0;

    printf("Enter a number: ");
    scanf("%d", &num);

    square = num * num;

    while (square != 0)
    {
        sumDigits += square % 10;
        square /= 10;
    }

    if (num == sumDigits)
    {
        printf("It is a Neon number\n");
    }
    else
    {
        printf("It is not a Neon number\n");
    }

    return 0;
}

The output of the above c program; as follows:

Enter a number: 9
It is a Neon number

C Program to Check Neon Number using Function

#include <stdio.h>

int isNeon(int num)
{
    int square, sumDigits = 0;
    square = num * num;

    while (square != 0)
    {
        sumDigits += square % 10;
        square /= 10;
    }

    if (num == sumDigits)
    {
        printf("It is a Neon number\n");
    }
    else
    {
        printf("It is not a Neon number\n");
    }
}

int main()
{
    int n;

    printf("Enter a number: ");
    scanf("%d", &n);
    
    isNeon(n);


    return 0;
}

The output of the above c program; as follows:

Enter a number: 1
It is a Neon number

Recommended C Programs

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

One reply to C Program to Check Neon Number

  1. I appreciate your work.

Leave a Reply

Your email address will not be published. Required fields are marked *