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


Please Help Members By Posting Answers For Below Questions

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.

4487


Are global variables static in c?

666


How do we print only part of a string in c?

579


show how link list can be used to repersent the following polynomial i) 5x+2

1673


Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?

683






Why is a semicolon (;) put at the end of every program statement?

620


What is malloc and calloc?

569


Who developed c language and when?

573


the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?

557


Can include files be nested?

619


What does sizeof int return?

586


Is that possible to add pointers to each other?

892


Which is better pointer or array?

592


What are identifiers c?

560


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

650