Advertisement
dragonbs

Strong Number

Feb 2nd, 2023
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.40 KB | None | 0 0
  1. int number = int.Parse(Console.ReadLine());
  2. int numberCopy = number;
  3. int sum = 0;
  4.  
  5. while (numberCopy > 0)
  6. {
  7.     int digit = numberCopy % 10;
  8.     numberCopy = numberCopy / 10;
  9.     int factorial = 1;
  10.  
  11.     for (int i = 1; i <= digit; i++)
  12.     {
  13.         factorial *= i;
  14.     }
  15.     sum += factorial;
  16. }
  17. if (sum == number)
  18. {
  19.     Console.WriteLine("yes");
  20. }
  21. else
  22. {
  23.     Console.WriteLine("no");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement