Monday, April 11, 2016

C program to find fabonacci series upto n using recursive technique

#include<stdio.h>
int fab(int i)
 {
  if(i==0)
   {
    return 0;
   }
  else if(i==1)
   {
    return 1;
   }
  else
   return fab(i-1)+fab(i-2);
 }
void main()
 {
  int n;
  printf("Enter no of terms");
  scanf("%d",&n);
  int i;
  for(i=0;i<n;i++)
   {
    printf(" %d ",fab(i));
   }
 
 }
output
Enter no of terms 6
0 1 1 2 3 5

No comments:

Post a Comment