Advertisement
yanass

Untitled

May 24th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Strong_Number
  8. {
  9.     class Program
  10.     {
  11.         //calculate factorial
  12.         static int Factorial(int digit)
  13.         {
  14.             int factorial = 1;
  15.             for (int i = 1; i <= digit; i++)
  16.                 factorial *= i;
  17.             return factorial;
  18.  
  19.         }
  20.         static void Main(string[] args)
  21.         {
  22.             int number = int.Parse(Console.ReadLine());
  23.             int sum = 0;
  24.             int workingNumber = number;
  25.             while (workingNumber > 0)
  26.             {
  27.                 int digit = workingNumber % 10;
  28.                 //sum factorials below
  29.                 sum += Factorial(digit);
  30.                 workingNumber /= 10;
  31.             }
  32.             if (number == sum)
  33.                 Console.WriteLine("yes");
  34.             else
  35.                 Console.WriteLine("no");
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement