| 发表于:2007-07-04 19:29:032楼 得分:40 |
jk 2002-02-22的代码。 http://topic.csdn.net/t/20011022/19/334766.html jk用的是递归,multin用的是循环。(循环的效率应该会好点) 进制是一样的(都是用10000000000进制)(能达到精度的前提下,进制越大,速度越快) <html> <head> <meta http-equiv= "content-type " content= "text/html; charset=gb2312 "> <meta name= "generator " content= "microsoft frontpage 4.0 "> <meta name= "progid " content= "frontpage.editor.document "> <title> 计算的阶乘 </title> </head> <body> 计算 <input name= "themaxinput " maxlength=4> 的阶乘, <input value=开始 type=submit onclick= "javascript:nowstart(themaxinput.value*1+1) "> <br> <font color=red size=-1> 注:将鼠标移到这里,按右键,点击查看源文件,可以看到详细程式 </font> </body> </html> <script language=javascript> var a=new array(1,0); //结果 var i; //循环1-1000 function nowstart(themax) {document.write ( " <br> 计算 "+(themax-1)+ "的阶乘 "); document.write ( " <br> 开始时间: "+date()+ " <br> 结果: <br> "); for (i=1;i <themax;i++) achengi(a,i); document.write ( " <br> 结束时间: "+date()); document.write ( " <br> 总长度为: "+a.reverse().join( ", ")); } function achengi(aa,ii) //实现递推相乘的步伐 { var c=0; var d=0; for (var l=0;(l <a.length) ¦ ¦(c> 0);l++) { if (l> =a.length) a[l]=0; d=c+a[l]*i; a[l]=d%10000000000; c=(d-a[l])/10000000000; } } </script> | | |
|