Introduction
A neon number is a positive integer, which is equal to the sum of the digits of its square.
For example, 9 is a neon number, because 9 squared = 81, and the sum of the digits 8 + 1 = 9, which is the same as the original number.
Write a program in C# to input an integer from the user, and check if that number is a Neon Number.
- using System;
-
- namespace ConsoleMultipleClass
- {
- class Program
- {
- static void Main(string[] args)
- {
- Program obj = new Program();
- obj.NeonNumber();
- Console.ReadLine();
- }
-
- void NeonNumber()
- {
- Console.WriteLine("Enter your number to check number is neon or not");
- int input = Convert.ToInt32(Console.ReadLine());
-
- int temp = input * input;
-
- string tempString = Convert.ToString(temp);
-
- char[] charArray = tempString.ToCharArray();
-
-
- int sum = 0;
- for (int i = 0; i < charArray.Length; i++)
- {
- string sumTemp = Convert.ToString(charArray[i]);
- sum += Convert.ToInt32(sumTemp);
- }
-
- if (sum == input)
- {
- Console.WriteLine("Number is neon");
- }
- else
- {
- Console.WriteLine("Number is not neon");
- }
- }
- }
- }
Summary
In this article, I have explained and provided examples of the neon number program in a simple way.