Check Neon Number

Check Neon Number in C++ (4 Programs)

IntermediateTopic: Advanced Number Programs
Back

C++ Check Neon Number Program

This program helps you to learn the fundamental structure and syntax of C++ programming.

Try This Code
#include <iostream>
using namespace std;

bool isNeon(int num) {
    int square = num * num;
    int sum = 0;
    
    while (square > 0) {
        sum += square % 10;
        square /= 10;
    }
    
    return sum == num;
}

int main() {
    int num;
    cout << "Enter a number: ";
    cin >> num;
    
    if (isNeon(num)) {
        cout << num << " is a Neon number" << endl;
    } else {
        cout << num << " is not a Neon number" << endl;
    }
    
    return 0;
}
Output
Enter a number: 9
9 is a Neon number

Understanding Check Neon Number

A Neon number is a number where the sum of digits of its square equals the number itself. For example, 9² = 81, and 8 + 1 = 9. This program demonstrates 4 different methods to check for neon numbers.

Note: To write and run C++ programs, you need to set up the local environment on your computer. Refer to the complete article Setting up C++ Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your C++ programs.

Table of Contents