民生银行2013年暑期实习生笔试编程题

来源:互联网 发布:黄金分析软件 编辑:程序博客网 时间:2024/05/16 08:53

题目是:求一个数N的阶乘末尾含有多少个0

解题思想:末尾0是由2*5的来的,所以考虑因式分解,得到有多少个2或者5,然后,对于一个数来说,被2整除的个数肯定比5多,所以这里只考虑被5整除的个数。

#include<iostream.h>main(){int a;cout<<"input the num you want to count"<<endl;    cin>>a;int temp=1;double Hook=1;int qq;int last=0;while(temp<=a){       Hook=Hook*temp;   temp++;}cout<<"Hook is "<<Hook<<endl;    cout<<"Now cout The Zero "<<endl;temp=1;while(temp<=a){      qq=temp;      while(qq%5==0)  {        last++;qq=qq/5;  }  temp++;}cout<<"The last is"<<last<<endl;}


原创粉丝点击