Advertisement
Stan0033

Untitled

Jun 13th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. using System;
  2.  
  3. namespace strong_number
  4. {
  5. class Program
  6. {
  7. // Write a program to check if a given number is a strong number or not.A number is
  8. // strong if the sum of the Factorial of each digit is equal to the number.For
  9. // example 145 is a strong number, because 1! + 4! + 5! = 145. Print "yes" if
  10. // the number is strong and “no” if the number is not strong.
  11. static void Main()
  12. {
  13. string Num = Console.ReadLine();
  14. long strongNum = long.Parse(Num);
  15. //-----------------------
  16. string answer = "no";
  17. //-----------------------
  18. foreach (char i in Num)
  19. {
  20. long Digit = long.Parse(i.ToString());
  21. Digit = factorial_Recursion(Digit);
  22. if (Digit == strongNum) { answer = "yes"; } else { answer = "no"; }
  23. }
  24. //-----------------------
  25. Console.WriteLine(answer);
  26. }
  27. public static long factorial_Recursion(long number)
  28. {
  29. int fact =1;
  30. for (int i = 1; i <= number; i++)
  31. {
  32. fact *= i;
  33. }
  34. return fact;
  35. }
  36. }
  37. }
  38.  
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement