Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //Write a program that calculates for given N how many trailing zeros present at the end of the number N!. Examples:
- //N = 10 --> N! = 3628800 --> 2
- //N = 20 ->> N! = 2432902008176640000 --> 4
- class CalculatesZero
- {
- static void Main()
- {
- int fact = int.Parse(Console.ReadLine());
- int zero = 0;
- double number = 0; // save current value of number multiplied by five
- for (int i = 1; i <= fact; i++)
- {
- number = i;
- while(number % 5 == 0)
- {
- zero++;
- number /= 5;
- if (number % 5 != 0) // if the number is divisible by five, repead the operation, else
- { // break , and get another i !
- break;
- }
- }
- }
- Console.WriteLine(zero);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement