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

Summary

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