C Program to Check a Neon Number

C Program to Check a Neon Number

A school number puzzle needs neon number for a nonnegative decimal value. Work on a copy so the original remains available for the final decision.

A neon number equals the sum of the decimal digits of its square.

Before this exercise, review integer division and remainders and loops. The worked program below applies those ideas to this specific problem.

  1. Explain

    Explain why neon number uses this sequence of operations.

  2. Trace

    Trace the sample values and predict the printed result.

  3. Apply

    Use 10, trace the digits and predict the reported result.

Neon Number: follow the data

  1. Given data

    A school number puzzle needs neon number for a nonnegative decimal value. Work on a copy so the original remains available for the final decision.

  2. Rule

    A neon number equals the sum of the decimal digits of its square.

  3. Observed result

    9: neon

A guided model of this example. The illustration explains the process; run the complete C program to check its output.

Understand the operation

Square the bounded original value, then extract the square’s digits and add them. Do not add the original number’s digits instead.

This is a numeric value exercise. Leading zeros in a printed identifier belong to text and are not preserved by an integer representation.

Read the complete C program

The input values are written into this complete C17 example so the calculation can be reproduced without an unavailable service. Change the named data, rebuild and compare the actual output with your prediction.

C17 · complete program

#include <stdio.h>
int main(void) {
  unsigned value = 9, remaining = value * value, sum = 0;
  do { sum += remaining % 10; remaining /= 10; } while (remaining != 0);
  printf("%u: %s\n", value, sum == value ? "neon" : "not neon");
  return 0;
}

Expected output

9: neon
Run in C compiler →

Follow the values through the code

C17 · code used in this explanation

#include <stdio.h>
int main(void) {
  unsigned value = 9, remaining = value * value, sum = 0;
  do { sum += remaining % 10; remaining /= 10; } while (remaining != 0);
  printf("%u: %s\n", value, sum == value ? "neon" : "not neon");
  return 0;
}

Start with the original value 9 and a separate working copy.

The digit operations produce the reported result: 9: neon.

Follow the worked calculation

  1. Start with the sample

    Start with the original value 9 and a separate working copy.

  2. Apply the rule

    The digit operations produce the reported result: 9: neon.

  3. Check the result

    9: neon

    9: neon
A guided model of this example. The illustration explains the process; run the complete C program to check its output.

Try a small variation

C17 · code used in this explanation

#include <stdio.h>
int main(void) {
  unsigned value = 9, remaining = value * value, sum = 0;
  do { sum += remaining % 10; remaining /= 10; } while (remaining != 0);
  printf("%u: %s\n", value, sum == value ? "neon" : "not neon");
  return 0;
}

Use 10, trace the digits and predict the reported result.

Worked answer

The changed input produces 10: not neon. The original remains separate from the shrinking copy so the final comparison or label can still refer to it.

C17 · complete program

#include <stdio.h>
int main(void) {
  unsigned value = 10, remaining = value * value, sum = 0;
  do { sum += remaining % 10; remaining /= 10; } while (remaining != 0);
  printf("%u: %s\n", value, sum == value ? "neon" : "not neon");
  return 0;
}

Expected output

10: not neon
Run in C compiler →

Recognize the important boundaries

These fixtures stay below 10000. A general reversed value or square can overflow even when the input itself fits; validate the chosen domain or check each multiply/add.

Negative inputs need an explicit sign policy. Do not assume negating the minimum signed integer is representable.

Check your understanding

Choose the answer, then compare the reasoning for every option.

Why preserve the original number?
Choose one answer. You can try again.

Answer and explanation

Digit removal changes the working copy.

Correct. The operation’s boundary and original-value contract must be maintained.

Use the idea independently

A neon number equals the sum of the decimal digits of its square.

Continue with separate stored values.

Language reference: WG14 C11 committee draft. These examples use the C17-compatible subset of the explained language features.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: C Program to Print Simple Pyramid Pattern →