Neon Number In C#

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.
  1. using System;  
  2.   
  3. namespace ConsoleMultipleClass  
  4. {  
  5.     class Program  
  6.     {  
  7.         static void Main(string[] args)  
  8.         {  
  9.             Program obj = new Program();  
  10.             obj.NeonNumber();  
  11.             Console.ReadLine();  
  12.         }  
  13.   
  14.         void NeonNumber()  
  15.         {  
  16.             Console.WriteLine("Enter your number to check number is neon or not");  
  17.             int input = Convert.ToInt32(Console.ReadLine());  
  18.   
  19.             int temp = input * input;  
  20.   
  21.             string tempString = Convert.ToString(temp);  
  22.   
  23.             char[] charArray = tempString.ToCharArray();  
  24.   
  25.   
  26.             int sum = 0;  
  27.             for (int i = 0; i < charArray.Length; i++)  
  28.             {  
  29.                 string sumTemp = Convert.ToString(charArray[i]);  
  30.                 sum += Convert.ToInt32(sumTemp);  
  31.             }  
  32.   
  33.             if (sum == input)  
  34.             {  
  35.                 Console.WriteLine("Number is neon");  
  36.             }  
  37.             else  
  38.             {  
  39.                 Console.WriteLine("Number is not neon");  
  40.             }  
  41.         }  
  42.     }  
  43. }  

Summary

 
In this article, I have explained and provided examples of the neon number program in a simple way.