Problem
Write an algorithm which computes the number of trailing zeros in n factorial.
Solution
[cpp]
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int n = 100;
int m = n;
int num;
num = 0;
while( n / 5 > 0){
num += n / 5;
n /= 5;
}
cout << "factoral (" << m << ")" << " has " << num << " zero trailings. " << endl;
return 0;
}
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int n = 100;
int m = n;
int num;
num = 0;
while( n / 5 > 0){
num += n / 5;
n /= 5;
}
cout << "factoral (" << m << ")" << " has " << num << " zero trailings. " << endl;
return 0;
}