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
Why is it usually a bad idea to use gets()? Suggest a workaround.
What is the need of structure in c?
What are different types of operators?
Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.
What is c basic?
What is size of union in c?
the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b
What is pointer to pointer in c?
What are Macros? What are its advantages and disadvantages?
Can you please explain the difference between malloc() and calloc() function?
What are structure types in C?
When the macros gets expanded?
Why static variable is used in c?
What is volatile c?
What is realloc in c?