ellapt

6.13.NFactorialTrailingZeros

Dec 18th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. using System;
  2. class NFactorialTrailingZeros
  3. {
  4. static void Main()
  5. {
  6. string strNum;
  7. uint n;
  8. do
  9. {
  10. Console.Write("Please, enter an unsigned integer number 0 < N <= 50000: ");
  11. }
  12. while ((!uint.TryParse(strNum = Console.ReadLine(), out n)) || n == 0 || n > 50000);
  13. uint primeDiv5 = 5;
  14. uint count=0;
  15. while (n%primeDiv5==0)
  16. {
  17. count+=n/primeDiv5;
  18. primeDiv5*=primeDiv5;
  19. }
  20. Console.WriteLine("{0} factorial has {1} trailing zeros.", n, count);
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment