Description

Write a c program to check that given number is Neon or Not.

What is Neon Number?

A neon number is a number if the sum of the square of that number is equal to the actual number, then it is a neon number. For Example : 9 is a neon number.

Let's check 9 is really neon or not. So the square of 9 is 81.

Now the sum of square each digits 8 + 1 = 9.

So, this is neon number.

Now let's start the code...

#include<stdio.h>

int main(){

    int n;
    printf("Enter the number : ");
    scanf("%d", &n);

    // sqaure the given number
    int sq = n * n;

    // declare a variable for storing the sum
    int sum = 0;

    while(sq>0){
        int digit = sq % 10;
        sum = sum + digit;
        sq = sq / 10;
    } 

    if(n == sum){
        printf("%d is Neon Number", n);
    }
    else{
        printf("%d is Not Neon Number", n);
    }

    return 0;
}

Output :

Enter the number : 9
9 is Neon Number

How it's work?

Step 1 : Initilized a variable n, which store the given number by user.

Step 2 : Print a message for user and enhance readibility.

Step 3 : Take Input from user using scanf() function.

Step 4 : Initilized a variable sq, which store the sqaure of given number, and sum is store the addition of each digit of square.

Step 5 : Start while loop, and this loop is valid when the condition ( sq > 0 ) is true, then execute the loop body Repeat(Step 6).

Step 6 : In loop body , initilized a variable digit, this variable store the value of last digit of square, and sum = sum + digit , this is store sum of digit of sum, and remove the last digit with this piece of code ( sq = sq / 10 ), when loop not go to teminated, then the loop body executed.

Step 7 : Compare both given number ( n ) and sum , if sum and n is both are equal then print the given number is Neon otherwise both are not equal then print the given number is not equal.

 

Algorithem Neon Number: 

  1. TAKE INPUT ( n )
  2. SET sq = n * n
  3. SET sum = 0
  4. REPEAT 5, 6, 7 while sq > 0
  5. SET int digit = sq % 10;
  6. sum = sum + digit;
  7. sq = sq / 10;
  8. CHECK ( n == sum ) then PRINT GIVEN NUMBER IS NEON NUMBER , CONDITION IS NOT TRUE GO TO STEP 9
  9. PRINT GIVEN NUMBER IN NOT NEON NUMBER.
  10. EXIT

 

Comments

Login is mandatory to comment Please login

Recommended Posts

C programming restaurant menu code | @lapmos

In this tutorial we write a c program which print the menus of restaurant with product and price.

Primary Arithmetic program in c programming and cpp programming language

Write a c and c++ programming language , primary Arithmetic Program

Automorphic Number | C programming language | @lapmos

An automorphic number is a number that has the same digit at the end of the square as the given number is an automorphic number. For Example : 25 is a Automorphic Number.

9 basic program in cpp programming language | @lapmos

In this post we write the 9 basic program in c programming language which is based the basic understanding of c++ programming language.

Spy Number | c programming

Today we are going to write a program which is to check if given number is spy or not and yes the most important thing is what is spy number, you will get the answer of all these on this blog.

Display Name of the month by accepting digit of the month | c programming

We will print the month name from the month number given by the user which will give us the user input. For Example : User Entered 5 then print