Advertisement
aslv

Trailing Zeroes in N! (N Factorial)

Apr 14th, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. using System;
  2.  
  3. namespace TrailingZeroesInNFactorial
  4. {
  5.     class Trail0
  6.     {
  7.         static void Main()
  8.         {
  9.             Console.Write("n = ");
  10.             uint n = uint.Parse(Console.ReadLine());
  11.             uint power5 = 5U, zeroes = 0U;
  12.             while (power5 <= n)
  13.             {
  14.                 zeroes += (uint)(n / power5);
  15.                 power5 *= 5;
  16.             }
  17.             Console.WriteLine(zeroes);
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement