C Program to find generate the fibonacci numbers using Recursion..

#include<stdio.h>

int fibonacci(int n)
{
 if(n==1)
  return 0;
 else if(n==2)
  return 1;
 else
  return fibonacci(n-1)+fibonacci(n-2);
}

void main()
{
 int n,i;
 printf("Enter the no of fibonacci terms to display..");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
  printf("%d\n",fibonacci(i));
 }
}

No comments:

Post a comment