大数阶乘

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int maxn=40000;


int a[maxn];
int BigJC(int n)
{
? ? int i,j;
? ? memset(a,sizeof(a));
? ? a[0]=1;
? ? for(i=2; i<=n; i++)
? ? {
? ? ? ? int c=0;
? ? ? ? for(j=0; j<maxn; j++)
? ? ? ? {
? ? ? ? ? ? int s=a[j]*i+c;
? ? ? ? ? ? a[j]=s%10;
? ? ? ? ? ? c=s/10;
? ? ? ? }
? ? }
}

int main()
{
? ? int n;
? ? int i,j;
? ? while(~scanf("%d",&n))
? ? {
? ? ? ? BigJC(n);
? ? ? ? for(j=maxn-1; j>=0; j--)//去除“前”导零;
? ? ? ? ? ? if(a[j])
? ? ? ? ? ? ? ? break;
? ? ? ? for(i=j; i>=0; i--)
? ? ? ? ? ? printf("%d",a[i]);
? ? ? ? printf("\n");
? ? }
? ? return 0;
}

dawei

【声明】:北京站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。