Advertisement
bacco

Factorial Trailing Zeroes

May 28th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. class MainClass
  5. {
  6.     static void Main()
  7.     {
  8.         BigInteger  num = BigInteger.Parse(Console.ReadLine());
  9.  
  10.         BigInteger facturel = FactorialCalc(num);
  11.  
  12.         Console.WriteLine(CountZeros(facturel));
  13.     }
  14.  
  15.     static BigInteger FactorialCalc(BigInteger  num)
  16.     {
  17.         BigInteger sum = num;
  18.         for (BigInteger i = num - 1 ; i >= 1; i--)
  19.         {
  20.             sum *= i;
  21.         }
  22.         return sum;
  23.     }
  24.  
  25.     static BigInteger CountZeros(BigInteger facturel)
  26.     {
  27.         var counter = 0;
  28.         while (facturel > 0)
  29.         {
  30.             var temp = facturel % 10;
  31.              
  32.             if (temp == 0)
  33.             {
  34.                 counter++;
  35.             }
  36.             else
  37.             {
  38.                 return counter;
  39.             }
  40.             facturel = facturel / 10;
  41.         }
  42.         return counter;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement