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
if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.
Are global variables static in c?
How do we print only part of a string in c?
show how link list can be used to repersent the following polynomial i) 5x+2
Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?
Why is a semicolon (;) put at the end of every program statement?
What is malloc and calloc?
Who developed c language and when?
the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?
Can include files be nested?
What does sizeof int return?
Is that possible to add pointers to each other?
Which is better pointer or array?
What are identifiers c?
any restrictions have on the number of 'return' statements that may be present in a function. a) no restriction b) only 2 return statements c) only 1 return statements d) none of the above