aggressiveviking

Untitled

Mar 19th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06.StrongNumber
  4. {
  5.     class StrongNumber
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = Console.ReadLine();
  10.  
  11.             int digit = input.Length;
  12.  
  13.             int number = int.Parse(input);
  14.             int strongNumber = number;
  15.  
  16.             int sum = 0;
  17.             int factorial = 0;
  18.             int factorialSum = 1;
  19.  
  20.             for (int i = 0; i < digit; i++)
  21.             {
  22.                 factorial = number % 10;
  23.  
  24.                 for (int a = 1; a <= factorial; a++)
  25.                 {
  26.                     factorialSum *= a;
  27.                 }
  28.                
  29.                 sum += factorialSum;
  30.  
  31.                 factorialSum = 1;
  32.                 factorial = 0;
  33.                 number /= 10;
  34.             }
  35.                        
  36.             if (sum == strongNumber)
  37.             {
  38.                 Console.WriteLine("yes");
  39.             }
  40.             else
  41.             {
  42.                 Console.WriteLine("no");
  43.             }
  44.         }
  45.     }
  46. }
Add Comment
Please, Sign In to add comment