JosepRivaille

X97024: Nombre de zeros al factorial

Apr 9th, 2015
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int nzeros_fact(int x) {
  6.     int nzf = 0;
  7.     for (int i = x; i >= 5; i = i/5) {
  8.         nzf = nzf + (i/5);
  9.     }
  10.     return nzf;
  11. }
  12.  
  13. //Pre: Llegeix un nombre
  14. //Post: Diu quants zeros té al final del factorial
  15. int main() {
  16.     int x;
  17.     while (cin >> x) {
  18.         cout << nzeros_fact(x) << endl;
  19.     }  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment