用递归调用的方式求解菲波拉奇数的第项的c语言程序
答案:1 悬赏:60 手机版
解决时间 2021-11-13 23:09
- 提问者网友:ミ烙印ゝ
- 2021-11-13 10:25
用递归调用的方式求解菲波拉奇数的第项的c语言程序
最佳答案
- 五星知识达人网友:时间的尘埃
- 2021-11-13 10:34
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
int myFBNC(int n){
if(n==1 || n==0)
return 1;
else return myFBNC(n-1)+myFBNC(n-2);
}
int main(void){
int n;
printf("Is which one?
n=");
scanf("%d",&n);
printf("The FBNC series item %d is %d
",n,myFBNC(n));
return 0;
}上述代码从第0项开始。若想从第1项开始,将函数中n==0改为n==2。
#include "stdio.h"
int myFBNC(int n){
if(n==1 || n==0)
return 1;
else return myFBNC(n-1)+myFBNC(n-2);
}
int main(void){
int n;
printf("Is which one?
n=");
scanf("%d",&n);
printf("The FBNC series item %d is %d
",n,myFBNC(n));
return 0;
}上述代码从第0项开始。若想从第1项开始,将函数中n==0改为n==2。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯