GerganaTsirkova

Factorial Trailing zeroes

Dec 8th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace FactorialTrailingZeroes
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. int number = int.Parse(Console.ReadLine());
  15. BigInteger result = CalculatingFactoriel(number);
  16. BigInteger numberOfZeroes = CountingZeroes(result);
  17. Console.WriteLine(numberOfZeroes);
  18. }
  19.  
  20. static BigInteger CountingZeroes(BigInteger result)
  21. {
  22. int counter = 0;
  23.  
  24. do
  25. {
  26. BigInteger num = result % 10;
  27. if (num % 10 == 0)
  28. counter++;
  29. result /= 10;
  30. }
  31. while (result % 10 == 0);
  32. return counter;
  33. }
  34.  
  35. static BigInteger CalculatingFactoriel(BigInteger number)
  36. {
  37. BigInteger result = 1;
  38. for (int i = 1; i <= number; i++)
  39. {
  40. result *= i;
  41. }
  42. return result;
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment