ššIntermediate
Check Whether Number is Neon Number
Check if sum of digits squared equals number
A Neon Number is a number where the sum of digits of its square equals the number itself. For example, 9 is a neon number because 9² = 81 and 8 + 1 = 9.
š Examples
ā 9 is Neon
9² = 81 ā 8+1 = 9
ā 1 is Neon
1² = 1 ā 1 = 1
ā 5 is NOT Neon
5² = 25 ā 2+5 = 7 ā 5
ā 12 is NOT Neon
12² = 144 ā 1+4+4 = 9 ā 12
C Program to Check Neon Number
neon_number.c
C
1#include <stdio.h>23int main() {4 int num, square, sum = 0, digit;5 6 printf("Enter a number: ");7 scanf("%d", &num);8 9 // Calculate square10 square = num * num;11 12 // Sum digits of square13 int temp = square;14 while (temp > 0) {15 digit = temp % 10; // Get last digit16 sum = sum + digit; // Add to sum17 temp = temp / 10; // Remove last digit18 }19 20 // Check if neon21 if (sum == num) {22 printf("%d is a Neon Number\n", num);23 printf("%d² = %d, Sum of digits = %d\n", num, square, sum);24 } else {25 printf("%d is NOT a Neon Number\n", num);26 printf("%d² = %d, Sum of digits = %d\n", num, square, sum);27 }28 29 return 0;30}Output
Enter a number: 9
9 is a Neon Number
9² = 81, Sum of digits = 9
š Code Explanation
| Code | Explanation |
|---|---|
| square = num * num | Calculate the square of the number |
| temp % 10 | Extract the last digit |
| temp / 10 | Remove the last digit |
| sum == num | Check if sum of digits equals original |
š” Fun Fact
There are only three single-digit neon numbers: 0, 1, and 9
šÆ Key Takeaways
āNeon: sum of digits of n² = n
āUse % 10 to get last digit
āUse / 10 to remove last digit
āOnly 0, 1, 9 are single-digit neons
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials