阶乘后面总共有多少个零

来源:互联网 发布:淘宝卖点优化 编辑:程序博客网 时间:2024/04/27 19:17

#include <iostream>
using namespace std;
int countzero(int st,int dt)
{
int count=0;
int i;
for (i=st;i<=dt;++i)
{
int temp=i;
while (temp%5==0)
{
++count;
temp/=5;
}
}
return count;
}
int main()
{
int n;
cout<<"请输入n"<<endl;
cin>>n;
cout<<countzero(1,n)<<endl;
system("PAUSE");
return 0;
}

原创粉丝点击