大數問題:求用一段C或C++程序寫求 f(x)=100! 的完整程序大數問題,
???
? 我用數組作的,輸出格式應該是是222,222,222?????
? #include?? "stdafx.h"??
? #include<stdio.h>??
? #include<stdlib.h>??
???
? int?? a[1000]={0};??
? int?? maxline=0;??
???
? void?? get(int?? n)??
? {??
? int?? i,j=0;??
? int?? temp=0;??
? int?? tail=0;??
? a[0]=1;??
????????? for(i=1;i<=n;i++)??
? {??
? j=0;??
????????????? while(j<=maxline)??
????? {??
????? a[j]=a[j]*i+temp;??
????? temp=a[j];??
????? if(temp>=1000)??
????? {??
????? tail=temp%1000;??
????????????? temp=temp/1000;??
????????????? a[j]=tail;??
????? if(j==maxline)??
????? {??
????????????????????????????????? maxline++;????????
????? }??
????? }??
????? else????
????? {??
????? tail=temp;??
????? temp=0;??
????? a[j]=tail;??
????? }??
????????????????????? j++;??
???????
????? }??
? }??
? }??
???
? int?? main(int?? argc,?? char*?? argv[])??
? {??
????????? int?? m;??
????????? int?? i=0;??
? printf("輸入要計算的階乘數:\n");??
? scanf("%d",&m);??
? fflush(stdin);??
????????? get(m);??
? printf("計算結果是:\n");??
???
? for(i=maxline;i>-1;i--)??
? {??
? printf("%d,",a[i]);??
? }??
???
? return?? 0;??
? }
轉載于:https://www.cnblogs.com/ruyi/archive/2009/07/28/1533513.html