有没有动C语言编程的,来看一下我的斐波拉契程序
#include<stdio.h>intKA(inta){if(a==0)return0;elseif(a==1)return1;elsereturnKA(a-1)+KA...
#include <stdio.h>
int KA(int a)
{
if(a == 0)
return 0;
else if(a == 1)
return 1;
else
return KA(a - 1) + KA(a - 2);
}
int main()
{
int N, x;
scanf("%d", &N);
x = KA(N);
printf("%d\n",x);
return 0;
}
上面的return KA(a - 1) + KA(a - 2);是怎么算的,如果a等于7的话,(7-1)+(7-2)=11.怎么运算之后变成13了、 展开
int KA(int a)
{
if(a == 0)
return 0;
else if(a == 1)
return 1;
else
return KA(a - 1) + KA(a - 2);
}
int main()
{
int N, x;
scanf("%d", &N);
x = KA(N);
printf("%d\n",x);
return 0;
}
上面的return KA(a - 1) + KA(a - 2);是怎么算的,如果a等于7的话,(7-1)+(7-2)=11.怎么运算之后变成13了、 展开
展开全部
KA(a-1)是指以a-1对为参数来调用KA函数。
这个KA函数是通过递归方式来计算斐波拉契值。
由函数可知:
KA(0) ==> 0
KA(1) ==> 1
KA(2) ==> KA(1) + KA(0) = 1 + 0 = 1
KA(3) ==> KA(2) + KA(1) = 1 + 1 = 2
KA(4) ==> KA(3) + KA(2) = 2 + 1 = 3
KA(5) ==> KA(4) + KA(3) = 3 + 2 =5
KA(6) ==> KA(5) + KA(4) = 5 + 3 = 8
KA(7) ==> KA(6) + KA(5) = 8 + 5 = 13
...
这个KA函数是通过递归方式来计算斐波拉契值。
由函数可知:
KA(0) ==> 0
KA(1) ==> 1
KA(2) ==> KA(1) + KA(0) = 1 + 0 = 1
KA(3) ==> KA(2) + KA(1) = 1 + 1 = 2
KA(4) ==> KA(3) + KA(2) = 2 + 1 = 3
KA(5) ==> KA(4) + KA(3) = 3 + 2 =5
KA(6) ==> KA(5) + KA(4) = 5 + 3 = 8
KA(7) ==> KA(6) + KA(5) = 8 + 5 = 13
...
展开全部
#include <stdio.h>
int KA(int a)
{
if(a == 1)
return 1;
else if(a == 2)
return 1;
else
return KA(a - 1) + KA(a - 2);
}
int main()
{
int N, x;
scanf("%d", &N);
x = KA(N);
printf("%d\n",x);
}
初值错了
斐波那契数列
1 1 2 3 5 8...
int KA(int a)
{
if(a == 1)
return 1;
else if(a == 2)
return 1;
else
return KA(a - 1) + KA(a - 2);
}
int main()
{
int N, x;
scanf("%d", &N);
x = KA(N);
printf("%d\n",x);
}
初值错了
斐波那契数列
1 1 2 3 5 8...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-06-18
展开全部
很简单!自己写
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询