Find Fibonacci using Recursion

#include<stdio.h>
#include<conio.h>
int fib(int n);
void main()
{
int n,f;
clrscr();
printf(“enter n\n”);
scanf(“%d”,&n);

f=fib(n);
printf(“f=%d”,f);
getch();
}
int fib(n)
{
if(n==1)
return 0;
if(n==2)
return 1;
else
return fib(n-1)+fib(n-2);
}

 

After running program 🙂

 

Leave a Reply