求c++代码

[复制链接]
查看11 | 回复0 | 2008-2-28 00:02:54 | 显示全部楼层 |阅读模式
这个方法最简单的了。不需要求出阶乘就知道0的个数#include #include using namespace std;]int ntrailingzero(int n){ int cnt = 0; while ( n /= 5 ) {cnt += n; //计算N!结尾零的个数 } return cnt;}int main(){ int total = 0; int number; cin>>number; total = ntrailingzero(number); cout<<"N!结尾零的个数:"<<total<<endl; system("pause"); return 0;}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行