Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language uses array to output the first 100 items of Fibonacci sequence, is there a negative number?
C language uses array to output the first 100 items of Fibonacci sequence, is there a negative number?
Because f[ 100] is a very large number, int can't be expressed at all, so it should be expressed by adding large numbers.

# include & ltstdio.h & gt

# include & ltstring.h & gt

Void sum (character a[], character b[])

{

int i,n,k;

for(i=strlen(b)- 1,k = 0; I & gt=0; k++,i -)

{

a[k]+= b[I]-' 0 ';

n = k;

while(a[n]>'9')

{

a[n+ 1]+=(a[n]--0 ')/ 10;

a[n]=(a[n]-' 0 ')% 10+' 0 ';

n++;

}

}

}

int main()

{

char a[ 10 1],b[ 10 1],fib[500][20 1]={0},ch;

int i,j,k,c,n;

strcpy(fib[ 1]," 1 ");

strcpy(fib[2]," 2 ");

fib[0][0]= ' 1 ';

for(I = 1; I< 10 1; i++)

fib[0][I]= ' 0 ';

for(I = 3; I & lt500; i++)

{

for(j = 0; j & lt20 1; j++)

fib[I][j]= ' 0 ';

}

for(I = 3; ; i++)

{

sum(fib[i],fib[I- 1]);

sum(fib[i],fib[I-2]);

for(j = 200; fib[I][j]= = ' 0 '; j-);

fib[I][j+ 1]= ' \ 0 ';

for(k = 0; k & lt= j; k++,j -)

{

ch = fib[I][k];

fib[I][k]= fib[I][j];

fib[I][j]= ch;

}

if(strlen(fib[I])& gt; 100 | |(strlen(fib[I])= = 10 1 & amp; & ampstrcmp(fib[i],fib[0])& gt; =0))

Break;

}

n = I;

for(I = 0; I< 100; i++)

{

printf("fib[%d]=%s\n ",I,fib[I]);

}

/*while(scanf("%s%s ",a,b)! EOF & amp& amp(strcmp(a," 0 ")! =0||strcmp(b," 0 ")! =0))

{

c = 0;

for(I = 1; I < = n; i++)

{

if(strcmp(fib[i],a)>= 0 & amp& ampstrlen(fib[I])= = strlen(a)| | strlen(fib[I])& gt; strlen(a))

if(strcmp(b,fib[I])& gt; = 0 & amp& ampstrlen(b)= = strlen(fib[I])| | strlen(b)>strlen(fib[i])

c++;

}

printf("%d\n ",c);

}*/

}