欢迎来到天天文库
浏览记录
ID:12177823
大小:43.00 KB
页数:13页
时间:2018-07-16
《n的阶乘高精度算法解析(n factorial high-precision algorithm analysis)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、n的阶乘高精度算法解析(Nfactorialhigh-precisionalgorithmanalysis)Inanfactorial,nisgreaterthan16nfactorialresultsalwaysoverflowlongplasticpreservation,forjustlearningCstudentsalwaysfeelverydifficult,soBaiduinthesearchboxtype"factorial"twocharactersinsearchresults,"Baiduenc
2、yclopedia"interpretation,openthepage,andturndown,sawa"highprecisionfactorial"noftheCcode:#include#defineN5000ittoholdlargernumber//modifyIntmain(void){Int,N,I,J,s,up,f[N]={0};Scanf("%d",&n);For(I=2,f[0]=1;I3、10;Up=s/10;}For(I=N-1;f[i]=0;i--);For(;I>=0;i--)printf(%d,f[i]);Printf("");Return0;}Ifyoudon'tfeelgoodenoughtounderstand,youcanchangetothefollowingcode,andyou'llprobablygetalittlebetter:#include#defineN5000ittoholdlargernumber//modifyIntmain(void){In4、t,N,I,J,s,up,f[N]={0};Scanf("%d",&n);F[0]=1;For(I=2;I5、(I=N-1;f[i]=0;i--);For(;I>=0;i--)printf(%d,f[i]);Printf("");Return0;}Whenwefirstcontactthiscode,willyoufeelveryhelpless?Don'tyouseewhyyoudothat?Here'smyunderstandingofthecode:Firstofall,inordertounderstandhowthisstringofcodeworks,thebestwayistofindanumbertota6、kein,findagoodwhitepaper,writewell,drawapicture,from0to5.Inessence,justtake5withyou,because...0!*1=1!;1!*2=2!;2!*3=3!;3!*4=4!;4!*5=5!;But3!=6<10;4;=24isjustover10;taking5ismoreuniversal.Let'stalkaboutwhathappenedwhenwewereinn=5.Sincetheouterloopstartswithi=2,we7、startwithi=2.Theinnerloopisfor(j=0,up=0;js=f[0]*2+0=1*2+0=2;F[j]=s%10;----->f[0]=2%10=2;Up=s/10;----->up=2/10=0;TwoJ=1:s=f[j]*i+up;----->s=f[1]*2+0=0*2+0=0;F[j]=s%10;----->f[1]=0%10=0;Up=s/10;----->up=0/10=0;Whenthejisgr8、eaterthanorequalto2,thecaseisthesameas"2.",andtheresultis:f[0]=2;f[1]=0;f[2]=0...Two:i=31.j=0:s=f[j]*i+up;----->s=f[0]*3+0=2*3+0=6;F[j]=s%10;----->f[0]=6%10=6;Up=s/10;----->
3、10;Up=s/10;}For(I=N-1;f[i]=0;i--);For(;I>=0;i--)printf(%d,f[i]);Printf("");Return0;}Ifyoudon'tfeelgoodenoughtounderstand,youcanchangetothefollowingcode,andyou'llprobablygetalittlebetter:#include#defineN5000ittoholdlargernumber//modifyIntmain(void){In
4、t,N,I,J,s,up,f[N]={0};Scanf("%d",&n);F[0]=1;For(I=2;I5、(I=N-1;f[i]=0;i--);For(;I>=0;i--)printf(%d,f[i]);Printf("");Return0;}Whenwefirstcontactthiscode,willyoufeelveryhelpless?Don'tyouseewhyyoudothat?Here'smyunderstandingofthecode:Firstofall,inordertounderstandhowthisstringofcodeworks,thebestwayistofindanumbertota6、kein,findagoodwhitepaper,writewell,drawapicture,from0to5.Inessence,justtake5withyou,because...0!*1=1!;1!*2=2!;2!*3=3!;3!*4=4!;4!*5=5!;But3!=6<10;4;=24isjustover10;taking5ismoreuniversal.Let'stalkaboutwhathappenedwhenwewereinn=5.Sincetheouterloopstartswithi=2,we7、startwithi=2.Theinnerloopisfor(j=0,up=0;js=f[0]*2+0=1*2+0=2;F[j]=s%10;----->f[0]=2%10=2;Up=s/10;----->up=2/10=0;TwoJ=1:s=f[j]*i+up;----->s=f[1]*2+0=0*2+0=0;F[j]=s%10;----->f[1]=0%10=0;Up=s/10;----->up=0/10=0;Whenthejisgr8、eaterthanorequalto2,thecaseisthesameas"2.",andtheresultis:f[0]=2;f[1]=0;f[2]=0...Two:i=31.j=0:s=f[j]*i+up;----->s=f[0]*3+0=2*3+0=6;F[j]=s%10;----->f[0]=6%10=6;Up=s/10;----->
5、(I=N-1;f[i]=0;i--);For(;I>=0;i--)printf(%d,f[i]);Printf("");Return0;}Whenwefirstcontactthiscode,willyoufeelveryhelpless?Don'tyouseewhyyoudothat?Here'smyunderstandingofthecode:Firstofall,inordertounderstandhowthisstringofcodeworks,thebestwayistofindanumbertota
6、kein,findagoodwhitepaper,writewell,drawapicture,from0to5.Inessence,justtake5withyou,because...0!*1=1!;1!*2=2!;2!*3=3!;3!*4=4!;4!*5=5!;But3!=6<10;4;=24isjustover10;taking5ismoreuniversal.Let'stalkaboutwhathappenedwhenwewereinn=5.Sincetheouterloopstartswithi=2,we
7、startwithi=2.Theinnerloopisfor(j=0,up=0;js=f[0]*2+0=1*2+0=2;F[j]=s%10;----->f[0]=2%10=2;Up=s/10;----->up=2/10=0;TwoJ=1:s=f[j]*i+up;----->s=f[1]*2+0=0*2+0=0;F[j]=s%10;----->f[1]=0%10=0;Up=s/10;----->up=0/10=0;Whenthejisgr
8、eaterthanorequalto2,thecaseisthesameas"2.",andtheresultis:f[0]=2;f[1]=0;f[2]=0...Two:i=31.j=0:s=f[j]*i+up;----->s=f[0]*3+0=2*3+0=6;F[j]=s%10;----->f[0]=6%10=6;Up=s/10;----->
此文档下载收益归作者所有