public static void Main()
Console.WriteLine("Happy Number. ");
Console.Write("Enter a number: ");
userInput = Console.ReadLine();
if (Int32.TryParse(userInput, out num) == true)
while (result != 1 && result != 4)
result = happyNum(result);
Console.WriteLine(num + " is a happy number. ");
Console.WriteLine(num + " is not a happy number. ");
Console.WriteLine(" ... ");
Console.WriteLine("Allowed input is only from 1 to 20,000. ");
Console.WriteLine("Zero or negative input is not allowed. ");
} while(num > 20000 || num < 1);
public static int happyNum(int num)
sum = sum + (modulo * modulo);