编写递归函数用来求斐波那契数列中第n项的值

1,1,2,3,5,8,13,21
2024-11-23 01:25:48
推荐回答(1个)
回答1:

#include
long int fn(int);
void main()
{
printf("%d",fn(10));
}

long int fn(int m)
{
long int temp;
if ((1 == m) | (2 == m))
temp = 1;

else
temp = fn(m - 1) + fn(m -2);

return temp;

}