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
What is context in c?
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
What is the purpose of the statement: strcat (S2, S1)?
If i have an array 0 to 99 i.e,(Size 100) I place the values 1 to 100 randomly like a[0]=29,a[1]=56 upto array[99].. the values are only between 1 to 100. getting the array values by using scanf.. If i entered one wrong element value line a[56]=108. how can i find it.. and also how to find the missing value in 1 to 100.. and i want to replace the missing values.. any one of them know please post your answer..
Can you please explain the difference between strcpy() and memcpy() function?
Write a program to print factorial of given number using recursion?
How was c created?
What is external variable in c?
Why is c called a mid-level programming language?
How does #define work?
What is the difference between the = symbol and == symbol?
What does *p++ do? What does it point to?
What does the format %10.2 mean when included in a printf statement?
What is s or c?