编写递归函数用来求斐波那契数列中第n项的值1,1,2,3,5,8,13,21

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/12 07:44:04
编写递归函数用来求斐波那契数列中第n项的值1,1,2,3,5,8,13,21

编写递归函数用来求斐波那契数列中第n项的值1,1,2,3,5,8,13,21
编写递归函数用来求斐波那契数列中第n项的值
1,1,2,3,5,8,13,21

编写递归函数用来求斐波那契数列中第n项的值1,1,2,3,5,8,13,21
#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;
}