Advertisement
Guest User

Strong Number

a guest
Jan 23rd, 2019
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06StrongNumber
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int number = int.Parse(Console.ReadLine());
  10.             int copyNumber = number;
  11.  
  12.             int currentNumber = 0;
  13.             int factorialSum = 0;
  14.  
  15.             while (copyNumber != 0)
  16.             {
  17.                 currentNumber = copyNumber % 10;
  18.                 copyNumber = copyNumber / 10;
  19.                
  20.                 int factorial = 1;
  21.  
  22.                 for(int i = 1; i <= currentNumber; i++)
  23.                 {
  24.                     factorial = factorial * i;
  25.                 }
  26.                 factorialSum = factorialSum + factorial;
  27.             }
  28.             if (number == factorialSum)
  29.             {
  30.                 Console.WriteLine("yes");
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine("no");
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement