题目:找到阶乘最后面的非零位。举个例子:5!=120所以5!的最后面的非零位是2;7!=5040,所以最后面的非零位是4。输入包括一行,为一个整数N(N<4221)。输出包括一行,为输出N!最后面的非零数。
话不多说,上代码
/** * 找到阶乘最后面的非零位 * @param value */ function findSomeShu() { //this.value=value; this.chengjie=1; this.findWho= function () { var reg = /\d{1}/g; var value = this.chengjie.toString().match(reg); for(i=value.length-1,len=value.length;i>=0;i--){ if(value[i]!='0'&&value!=0){ return value[i]; } } } } var someShu=new findSomeShu(); /** * 计算乘阶 * @param value * @constructor */ findSomeShu.prototype.chengJie=function(value){ var chengjie=this.chengjie; coputeChengJie(); function coputeChengJie(){ if(value>1){ chengjie=chengjie*value; value--; coputeChengJie() } } this.chengjie=chengjie; return this.findWho(); }; someShu.chengJie(10);