Advertisement
dimitarbogdanov

factoriel

Jun 3rd, 2023
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. // resharper disable all
  2.  
  3. string input = Console.ReadLine()!;
  4.  
  5. int factorialSum = 0;
  6. for (int i = 0; i < input.Length; i++)
  7. {
  8.     char currentChar = input[i];
  9.     int parsedChar = int.Parse(currentChar.ToString());
  10.    
  11.     int factForThisChar = 1;
  12.     for (int j = 1; j <= parsedChar; j++)
  13.     {
  14.         factForThisChar = factForThisChar * j;
  15.     }
  16.  
  17.     factorialSum += factForThisChar;
  18. }
  19.  
  20. int inputParsed = int.Parse(input);
  21. int factForInput = 1;
  22. for (int i = 1; i <= inputParsed; i++)
  23. {
  24.     factForInput = factForInput * i;
  25. }
  26.  
  27. if (factForInput != factorialSum)
  28. {
  29.     Console.WriteLine("not equal :(");
  30. }
  31. else
  32. {
  33.     Console.WriteLine("equal!!! :D");
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement