A neon number is a number where the sum of digits of square of the number is equal to the number. For example, if the input number is 9, its square is 9*9 = 81 and the sum of the digits is 9. i.e. 9 is a neon.
In this program, you are going to learn that how to check a given number is neon or not.
Steps to check a given number is neon or not
1. Calculate the square of the given number.
2. Add each digit of the calculated square number.
3. compare the sum of digits of square of the number and number.
4. If the sum of digits equal to the number, then it is a neon otherwise it is not neon.
#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; //Ask to enter the number printf("Enter the number = "); scanf("%d",&data); // if is isNeonNumber is 1, then neon number isNeonNumber = isNeon(data); (isNeonNumber)? printf("neon number\n\n"):printf("Not a neon number\n\n"); return 0; }
Output:
You can also check the below articles,
You can also write a program to check and print neon numbers in a given range.
#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:
Recommended Articles for you:
- Find the prime number using the C program.
- Find all prime numbers up to n using trial division and Sieve of Eratosthenes algorithm.
- Check date validity in C?
- How to use if in C programming.
- C language character set.
- How to use C if-else condition?
- How to use for loop in C?
- Elements of C Language.
- Data type in C language.
- Operators with Precedence and Associativity.
- 100 C interview Questions.
- Program to Count Number of Words in a Given String and File.
- 5 ways to find factorial of a number in C.
- C Program to find the Range of Fundamental Data Types.
- Fibonacci Series Program In C: A simple introduction.
- How to use atoi() and how to make own atoi()?
- Program to check leap year in C language.
- How to use the structure of function pointer in c language?
- Create a students management system in C.
- Create an employee management system in C.
- Top 11 Structure Padding Interview Questions in C
- File handling in C.