Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace strong_number
- {
- class Program
- {
- // Write a program to check if a given number is a strong number or not.A number is
- // strong if the sum of the Factorial of each digit is equal to the number.For
- // example 145 is a strong number, because 1! + 4! + 5! = 145. Print "yes" if
- // the number is strong and “no” if the number is not strong.
- static void Main()
- {
- string Num = Console.ReadLine();
- long strongNum = long.Parse(Num);
- //-----------------------
- string answer = "no";
- //-----------------------
- foreach (char i in Num)
- {
- long Digit = long.Parse(i.ToString());
- Digit = factorial_Recursion(Digit);
- if (Digit == strongNum) { answer = "yes"; } else { answer = "no"; }
- }
- //-----------------------
- Console.WriteLine(answer);
- }
- public static long factorial_Recursion(long number)
- {
- int fact =1;
- for (int i = 1; i <= number; i++)
- {
- fact *= i;
- }
- return fact;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement