#include
<stdio.h>
#include
<stdlib.h>
#define
M
15000
unsigned
char
*add_s(unsigned
char
*,const
unsigned
char
*);
unsigned
char
char1[M];
unsigned
char
char2[M];
int
main()
{
unsigned
char
*fibo1=char1,*fibo2=char2,*temp;
long
int
i,n;
printf("您想知道第n个Fibonacci数是多少吗?请输入n:");
scanf("%ld",&n);
if
(n<=2)
{
printf("fib(%ld)=1",n);
return
0;
}
fibo1[0]=fibo2[0]=1;
for
(i=3;i<=n;i++)
{
temp=add_s(fibo1,fibo2);
fibo1=fibo2;
fibo2=temp;
}
for
(i=M-1;!fibo2[i];i--)
;
printf("fib(%d)
=
%d",n,fibo2[i]);
for
(i--;i>=0;i--)
printf("%02d",fibo2[i]);
putchar('\n');
return
0;
}
unsigned
char
*add_s(unsigned
char
*first,const
unsigned
char
*two)
{
unsigned
char
*p=first;
int
i,j,temp=0,flag=0;
for
(i=M-1;first[i]==0&&two[i]==0;i--)
;
for
(j=0;j<=i+1;j++)
{
temp+=first[j]+two[j];
first[j]=temp<100?temp:temp-100;
temp=temp<100?0:1;
}
return
first;
}
我懒的写这种无聊的东西.这是我坐我对面的同事在我回上个贴的时候给我的,LZ看看
现在的年轻人啊,冲动