此题要注意不能只算n/5,还要考虑n/5是5的倍数的情况下,要继续n/5。比如说25/5=5,那这个5还要考虑进去。
代码如下:
#include <iostream>
using namespace std;
int trailingZeroes(int n) {
int count=0;
while(n) {
n/=5;
count+=n;
}
return count;
}
int main()
{
cout<<trailingZeroes(25)<<endl;
return 0;
}