compute the nth mumber in the fibonacci sequence?
Answer Posted / ravi kumar gupta
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
void fib(int n);
clrscr();
printf("Enter any no.");
scanf("%d",&n);
clrscr();
printf("Hit any key to continue");
getch();
clrscr();
printf("Fibonacci of %d is \n");
fib(n);
getch();
}
void fib(int n)
{
static int x,y;
int temp;
if(n<=1)
{
x=0;
y=1;
}
else
{
fib(n-1);
temp=y;
y=x+y;
x=temp;
}
printf(" %d\n",x);
return;
}
| Is This Answer Correct ? | 10 Yes | 6 No |
Post New Answer View All Answers
Is it possible to pass an entire structure to functions?
What is scanf () in c?
In a header file whether functions are declared or defined?
What is a program?
What is the default value of local and global variables in c?
Is fortran still used in 2018?
Differentiate between a for loop and a while loop? What are it uses?
Compare array data type to pointer data type
Explain which function in c can be used to append a string to another string?
When should the const modifier be used?
What is const volatile variable in c?
What are bitwise shift operators in c programming?
find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }
Differentiate between #include<...> and #include '...'
What are the various types of control structures in programming?