LardaX

Factorial-Trailing-Zeroes

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