- 1C Hello World Program
- 2C Program to Print Your Own Name
- 3C Program to Print an Integer Entered by the User
- 4C Program to Add Two Numbers
- 5C Program to Multiply Two Floating‑Point Numbers
- 6C Program to Print the ASCII Value of a Character
- 7C Program to Swap Two Numbers
- 8C Program to Calculate Fahrenheit to Celsius
- 9C Program to Find the Size of int, float, double and char
- 10C Program - Add Two Complex Numbers
- 11C Program - Find Simple Interest
- 12C Program - Find Compound Interest
- 13C Program - Area And Perimeter Of Rectangle
- 14C Program - Check Whether a Number is Positive, Negative, or Zero
- 15C Program - Check Whether Number is Even or Odd
- 16C Program - Check Whether a Character is Vowel or Consonant
- 17C Program - Find Largest Number Among Three Numbers
- 18C Program - Calculate Sum of Natural Numbers
- 19C Program - Print Alphabets From A to Z Using Loop
- 20C Program - Make a Simple Calculator
- 21C Program - Generate Multiplication Table
- 22C Program - Reverse a Number
- 23C Program - Check whether the input number is a Neon Number
- 24C Program - Find All Factors of a Natural Number
C Program – Check Whether the Input Number is a Neon Number - Digit Sum of Square
Check Whether a Number is Neon
A neon number is defined as a number for which the sum of the digits of its square equals the number itself. For instance, 9 is a neon number because 9² = 81 and 8 + 1 = 9. This program reads an integer, computes its square, adds the digits of the square, and checks if this sum is equal to the original number.
#include <stdio.h>
int main() {
int n, square, sum = 0, rem;
printf("Enter an integer: ");
scanf("%d", &n);
square = n * n; // Compute the square
while (square != 0) {
rem = square % 10; // Extract the last digit
sum += rem; // Add it to the sum
square /= 10; // Remove the last digit
}
if (sum == n) {
printf("%d is a neon number.\n", n);
} else {
printf("%d is not a neon number.\n", n);
}
return 0;
}
Enter an integer: 9
9 is a neon number.
After computing the square, the program extracts each digit of the squared value, adds it to sum, and then checks if this sum equals the original number. If they match, the number satisfies the neon property.
⬅ Previous TopicC Program - Reverse a Number
Next Topic ⮕C Program - Find All Factors of a Natural Number
Next Topic ⮕C Program - Find All Factors of a Natural Number
Comments
Loading comments...