C PROGRAMMING PROGRAM • LOOPS & NUMBER PROBLEMS
Check Whether a Number Is Neon
Learn how to check whether a number is neon using a clear C program.
PROBLEM UNDERSTANDING
Input and expected output
Sample input
9
Sample output
Neon number
COMPLETE C PROGRAM
Complete C implementation
#include <stdio.h>
int main(void)
{
int number, square, sum = 0;
printf("Enter a non-negative integer: ");
scanf("%d", &number);
if (number < 0) {
printf("Use a non-negative integer.\n");
return 0;
}
square = number * number;
do {
sum += square % 10;
square /= 10;
} while (square > 0);
printf(sum == number ? "Neon number\n" : "Not a neon number\n");
return 0;
}CURRENT STEP
SELECTED LINE
EXPECTED OUTPUT FOR THE SAMPLE
Neon number
Step 0 of 0
PROGRAM EXPLANATION
Algorithm and explanation
- Read the required input values.
- Square the number, sum the square's digits and compare that sum with the original.
- Display the computed result.
Square the number, sum the square's digits and compare that sum with the original.
EFFICIENCY
Time and space complexity
Time complexity
O(d)
Auxiliary space
O(1)
DEBUGGING CHECKLIST
Common mistakes
Check this
Use the correct format specifier for every variable.
Check this
Initialize variables before using their values.
Check this
Check braces, semicolons and input order carefully.
Try it yourself
Practice: Run the program with the sample input, predict its output, and then test one boundary case of your own.
