大数的阶乘

来源:互联网 发布:java绘图教程 编辑:程序博客网 时间:2024/05/14 06:36
#include<iostream>using namespace std;int a[100000];int main(){ int N; while(scanf("%d",&N)!=EOF) {  int i,j;  int len,rest;//len表示当前的位数,rest表示进位;   a[1]=1;  len=1;  for(i=2;i<=N;i++)  {   for(j=1,rest=0;j<=len;j++)   {    a[j]=a[j]*i+rest;    rest=a[j]/10;    a[j]%=10;       }   while(rest>0)   {    a[j++]=rest%10;    rest/=10;    //printf("rest=%d\n",rest);   }   len=j-1;  }    for(i=len;i>0;i--)   printf("%d",a[i]);  printf("\n"); } return 0;}
	
				
		
原创粉丝点击