Advertisement
kuruku

TrailingZeroesInN

May 3rd, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2.  
  3. //Write a program that calculates with how many zeroes the factorial of a given number n has at its end.
  4. // Your program should work well for very big numbers, e.g. n=100000
  5.  
  6.     class TrailingZeroesInN
  7.     {
  8.         static void Main()
  9.         {
  10.             BigInteger n = BigInteger.Parse(Console.ReadLine());
  11.             BigInteger nFaktorial = 1;
  12.  
  13.  
  14.             for (int i = 1; i <= n; i++)
  15.             {
  16.                 nFaktorial *= i;
  17.             }
  18.             Console.WriteLine(nFaktorial);
  19.             int count = 0;
  20.             while (nFaktorial % 10 == 0)
  21.             {
  22.                 count++;
  23.                 nFaktorial = nFaktorial / 10;
  24.             }
  25.             Console.WriteLine("Zeros = " + count);
  26.         }
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement