Advertisement
Masovski

[C# Basics][Loops-HW] 18.* Trailing Zeroes in N!

Mar 29th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 0 0
  1. using System;
  2. using System.Numerics; // Note that you must add reference to System.Numerics
  3.  
  4. class TrailingZeroesInNFac
  5. {
  6.     static void Main()
  7.     {
  8.         int n = int.Parse(Console.ReadLine());
  9.         BigInteger factorial = 1;
  10.         int trailingZeroes = 0;
  11.  
  12.         for (int i = 1; i <= n; i++)
  13.         {
  14.             factorial *= i;
  15.         }
  16.  
  17.         while (factorial % 10 == 0)
  18.         {
  19.             trailingZeroes++;
  20.             factorial /= 10;
  21.         }
  22.         Console.WriteLine("Trailing Zeroes: {0}", trailingZeroes);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement