Fibonacci与递归 [英] Fibonacci with recursion
本文介绍了Fibonacci与递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你可以帮我解决这个问题吗?
#include< stdio.h>
#include< conio。 h>
void main()
{
int fib(int);
int n,f = 1,ans;
clrscr();
while(f == 1)
{
printf( \ n ***生成斐波那契系列***);
printf(\ nEn输入所需术语数量:);
scanf("%d"& n);
if(n< = 1)
{
printf(" \\\
Invalid Choice..Number Of Terms应该超过1);
printf(\ nDo你想再试一次...... \ n1.Yes \\\
2.No ;);
scanf("%d"& f);
}
else
{
printf(" \ nSeries:%d",fib(n));
f = 2;
}
}
getch();
}
int fib(int a)
{
if((a == 0)||(a == 1))
{
return(1);
}
其他
{
return(fib(a-1)+ fib(a-2));
}
}
i wat也打印d号...例如,如果n = 5
1 1 2 3 5
解决方案
@Tired
你该怎么做?
void fibfib(int n)
{
int q;
if(q = n-1)fibfib(q); printf("%d",fib( q));
}
wat = *想要...
umm我知道你输入的函数...你可以帮我理解它吗?如果你可以的话,它会很棒......
thnx ..
@Tired
请正确拼写你的单词;这是一个国际论坛而不是你当地的文字发言社区。
亲切的问候,
Jos
hey..
can u help me wid this..
#include<stdio.h>
#include<conio.h>
void main()
{
int fib(int);
int n,f=1,ans;
clrscr();
while(f==1)
{
printf("\n***Generating A Fibonacci Series***");
printf("\nEnter Number Of Terms Required: ");
scanf("%d",&n);
if(n<=1)
{
printf("\nInvalid Choice..Number Of Terms Should Be more Than 1");
printf("\nDo You Want To Try Again...\n1.Yes\n2.No");
scanf("%d",&f);
}
else
{
printf("\nSeries: %d",fib(n));
f=2;
}
}
getch();
}
int fib(int a)
{
if((a==0)||(a==1))
{
return(1);
}
else
{
return(fib(a-1)+fib(a-2));
}
}
i wat to print d numbers as well...eg if n =5
1 1 2 3 5
解决方案
@Tired
You what to what?
void fibfib(int n)
{
int q;
if(q=n-1)fibfib(q);printf("%d ",fib(q));
}
wat=*want...
umm i dint understand the func u hv typed..can u help me with understanding it???it wud b great if u can..
thnx..
@Tired
Please spell your words properly; this is an international forum not your local text speak community.
kind regards,
Jos
这篇关于Fibonacci与递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文