#include
<
stdio.h
>
void main()
... {
int N;
printf("please input the number:");
scanf("%d",&N);
Result = 0; // 最后的结果
while ( N >= 5 )
...{
N /= 5;
Result += N;
}
// 结束了。Result 里包含了0的个数。
printf("零的个数为:%d ",Result );
}
void main()
... {
int N;
printf("please input the number:");
scanf("%d",&N);
Result = 0; // 最后的结果
while ( N >= 5 )
...{
N /= 5;
Result += N;
}
// 结束了。Result 里包含了0的个数。
printf("零的个数为:%d ",Result );
}
遇到了这样的一道题,当时想了很久都没有想出来,要是说把N的阶乘给算出来,那可就是个大工程了,这个解决办法很是巧妙,求0的个数,就是求5的个数。
接下来,如何求5的个数呢?如果遍历一遍的话,那显然是太慢了!
最终的解决办法,就是那上面的四行代码,真让人汗颜。。。。