Advertisement
nikolov_k

13 Trailing zeros

Dec 6th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System;
  2.  
  3. class TrailingZeros
  4. {
  5.     static uint CountZero(uint number)
  6.     {
  7.         uint zeroCount = 0;
  8.         if (number % 5 == 0)
  9.         {
  10.             zeroCount++;
  11.             zeroCount += CountZero(number / 5);
  12.         }
  13.         return zeroCount;
  14.     }
  15.     static void Main()
  16.     {
  17.         Console.Write("Input positive integer number N ");
  18.         uint n = uint.Parse(Console.ReadLine());
  19.         uint zeroCount = 0;
  20.         for (uint i = 1; i <= n; i++)
  21.         {
  22.             zeroCount += CountZero(i);
  23.         }
  24.         Console.WriteLine("There are {0} trailing zeros in {1}!", zeroCount, n);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement