šŸ”€šŸ“š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>
2
3int main() {
4 int num, square, sum = 0, digit;
5
6 printf("Enter a number: ");
7 scanf("%d", &num);
8
9 // Calculate square
10 square = num * num;
11
12 // Sum digits of square
13 int temp = square;
14 while (temp > 0) {
15 digit = temp % 10; // Get last digit
16 sum = sum + digit; // Add to sum
17 temp = temp / 10; // Remove last digit
18 }
19
20 // Check if neon
21 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

CodeExplanation
square = num * numCalculate the square of the number
temp % 10Extract the last digit
temp / 10Remove the last digit
sum == numCheck 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