StoimenK

C# 2.6 Strong Number

Jan 23rd, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 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 _1._6_Strong_Number
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int num = int.Parse(Console.ReadLine());
  14. int tempNum = num;
  15. int totalFactorialSum = 0;
  16.  
  17. while (tempNum > 0)
  18. {
  19. int digit = tempNum % 10;
  20. tempNum /= 10;
  21.  
  22. int currentFactorialSum = 1;
  23.  
  24. for (int i = 1; i <= digit; i++)
  25. {
  26. currentFactorialSum *= i;
  27. }
  28.  
  29. totalFactorialSum += currentFactorialSum;
  30. }
  31. if (num == totalFactorialSum)
  32. {
  33. Console.WriteLine("yes");
  34. }
  35. else
  36. {
  37. Console.WriteLine("no");
  38. }
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment