|
楼主 |
发表于 2003-10-22 22:13:55
|
显示全部楼层
自己UP一下
[code:1]
#include <stdio.h>
#include <malloc.h>
#define MAXN 1000
void pnext(int a[], int k){
int *b, m=a[0], i, j, r, carry;
b=(int*)malloc(sizeof(int)*(m-1));
for(i=1; i<=m; i++) b[i]=a[i];
for(j=1; j<k; j++){
for(carry=0, i=1; i<=m; i++){
r=(i<=a[0]?a[i]+b[i]:a[i])+carry;
a[i]=r%10;
carry=r/10;
}
if(carry) a[++m]=carry;
}
free(b);
a[0]=m;
}
void write(int *a, int k){
int i;
printf("%4d!=", k);
for(i=a[0]; i>0; i--) printf('%d',a[i]);
printf("\n");
}
int main(int argc, char** argv){
int a[MAXN];
int n, k;
printf("Input the number n: ");
scanf(" %d", &n);
a[0]=1; a[1]=1; write(a, 1);
for(k=2; k<=n; k++){
pnext(a, k);
write(a, k);
getchar();
}
return 1;
}
[/code:1]
没有什么好说的......... |
|