首先需要明确的是,n稍微大一点longlong类型也受不了,所以按照通常的做法用数组来存放 代码如下 #include<stdio.h> //输入包含一个正整数n,n<=1000。 int main() { int n,i,j,a[3000]={0},temp1,temp2,k;//m用来计数 a[0]=1; scanf("%d",&n); for(i=1;i<=n;i++) { temp1=0; temp2=0; //m=0; for(j=0;j<3000;j++) { a[j]=a[j]i; // printf("%d&",a[j]); } for(j=0;j<3000;j++) { temp1=a[j]%10; temp2=a[j]/10; a[j]=temp1; a[j+1]=a[j+1]+temp2; // printf("%d**",a[j+1]); // m++; //if(temp10&&temp20&&a[j+1]==0) break;//说明无进位 } }
for(k=2999;k>=0;k--)
{
if(a[k]!=0) break;//记录位置
// printf("%d--",k);
}
for(i=k;i>=0;i--)
{
printf("%d",a[i]);
}
return 0;
}