Advertisement
mausha

Untitled

Feb 14th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. namespace E_FactorialTrailingZeroes
  2. {
  3. using System;
  4. using System.Numerics;
  5.  
  6. public class FactorialZeroes
  7. {
  8. public static void Main()
  9. {
  10. var number = int.Parse(Console.ReadLine());
  11. GetFactorial(number);
  12. }
  13.  
  14. public static void GetFactorial(int number)
  15. {
  16. BigInteger factorial = 1;
  17.  
  18. for (int i = 1; i <= number; i++)
  19. {
  20. factorial *= i;
  21. }
  22.  
  23. Console.WriteLine($"{number}! = {factorial} -> {GetTrailingZeroes(factorial)}");
  24. }
  25.  
  26. public static string GetTrailingZeroes(BigInteger factorial)
  27. {
  28. var counter = 0;
  29. for (int i = 0; i < factorial.ToString().Length; i++)
  30. {
  31. if (factorial % 10 == 0)
  32. {
  33. counter++;
  34. factorial /= 10;
  35. }
  36. else
  37. {
  38. break;
  39. }
  40. }
  41.  
  42. if (counter == 1)
  43. {
  44. return "One trailing zero";
  45. }
  46.  
  47. else
  48. {
  49. return counter + " trailing zeroes";
  50. }
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement