Advertisement
TzvetanIG

Trailing Zeroes in N!

Mar 23rd, 2014
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2.  
  3. class TrailingZeroesInNFactorial
  4. {
  5.     static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.         int countZero = 0;
  9.  
  10.         for (int i = 1; i <= n; i++)
  11.         {
  12.             if (i % 5 == 0)
  13.             {
  14.                 if (i % 10 == 0)
  15.                 {
  16.                     countZero += GetZero(i);
  17.                 }
  18.                 else
  19.                 {
  20.                     countZero++;
  21.                 }
  22.             }
  23.         }
  24.  
  25.         Console.WriteLine(countZero);
  26.     }
  27.  
  28.     static int GetZero(int number)
  29.     {
  30.         int count = 0;
  31.         while (number % 10 == 0)
  32.         {
  33.             number = number / 10;
  34.             count++;
  35.         }
  36.         return count++;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement