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

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of 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 from a starting stage. As well as demo example.

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 *