NastySwipy

Programming Fundamentals - 14. Factorial Trailing Zeroes

Apr 6th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. namespace _04b_MethodsDebuggingTroubleshootingCode_Exercises
  5. {
  6.     class MethodsDebuggingTroubleshootingCode_Exercises
  7.     {static void Main(string[] args)
  8.         {
  9.             BigInteger num = BigInteger.Parse(Console.ReadLine());
  10.            
  11.             Console.WriteLine($"{CalculateTrailingZeroes(Factorial(num))}");
  12.         }
  13.  
  14.         static BigInteger Factorial(BigInteger num)
  15.         {
  16.             if (num <= 1)
  17.                 return 1;
  18.             return num * Factorial(num - 1);
  19.         }
  20.  
  21.         static int CalculateTrailingZeroes(BigInteger num)
  22.         {
  23.             int zeroesCounter = 0;
  24.  
  25.             while (num % 10 == 0)
  26.             {
  27.                 zeroesCounter++;
  28.                 num /= 10;
  29.             }
  30.  
  31.             return zeroesCounter;
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment