问题八十九:Fibonacci数递归法(续问题八十八)
[plain]
#include <stdio.h>
int fibonacci(int num);
int main()
{
int num;
int sum;
printf("please enter a number:");
scanf("%d", &num);
sum=fibonacci(num);
printf("The result is %d\n", sum);
return 0;
}
int fibonacci(int num)
{
int sum;
if(num==1 || num==2)
{
sum=1;
}
else
{
sum=fibonacci(num-1)+ fibonacci(num-2);
}
return sum;
}
#include <stdio.h>
int fibonacci(int num);
int main()
{
int num;
int sum;
printf("please enter a number:");
scanf("%d", &num);
sum=fibonacci(num);
printf("The result is %d\n", sum);
return 0;
}
int fibonacci(int num)
{
int sum;
if(num==1 || num==2)
{
sum=1;
}
else
{
sum=fibonacci(num-1)+ fibonacci(num-2);
}
return sum;
}
补充:软件开发 , C语言 ,