Program to display fibonacci series using recursion

/* Fibonacci series using recursion */

#include<stdio.h>

#include<conio.h>

void main()

{

int fib(int ) ;

int i,r,n;

clrscr();

printf(“Enter How Many terms to be print \n”);

scanf(“%d”,&n);

printf(“Fibonacci series is :\n”);

for(i=1;i<=n;i++)

{

r=fib(i);// Calling with Argument

printf(“%5d”,r);

}

getch();

}

 

// Function definition

int fib(int x)

{

int f;

if (x==1)

return(0);

else if (x==2)

return(1);

else

f= fib(x-1)+fib(x-2);

return(f);

}

Mohit Arora
Follow me