用递归的方法解决Fibonacci数列问题
1
/*该程序用于打印Fibonacci数列的前N项*/
2
/*编写者:FeeFox*/
3
/***********************************************/
4
#include <stdio.h>
5![]()
6
int RecCount(int n);
7![]()
8
int main(void)
9
{
10
int n;
11![]()
12
printf("n=:");
13
scanf("%d",&n);
14
printf("%d",RecCount(n));
15
getchar();
16
return 0;
17
}
18![]()
19
int RecCount(int n)/*递归计算第n位的值*/
20
{
21
if ((n==1)||(n==2))
22
{
23
return 1;
24
}
25
else
26
{
27
return RecCount(n-1)+RecCount(n-2);
28
}
29
}
30
/* CopyRight @2006 FreeFox All right reserved */
31![]()
/*该程序用于打印Fibonacci数列的前N项*/2
/*编写者:FeeFox*/3
/***********************************************/4
#include <stdio.h>5

6
int RecCount(int n);7

8
int main(void)9
{10
int n;11

12
printf("n=:");13
scanf("%d",&n);14
printf("%d",RecCount(n));15
getchar();16
return 0;17
}18

19
int RecCount(int n)/*递归计算第n位的值*/20
{21
if ((n==1)||(n==2))22
{23
return 1;24
}25
else26
{27
return RecCount(n-1)+RecCount(n-2);28
}29
}30
/* CopyRight @2006 FreeFox All right reserved */31



浙公网安备 33010602011771号