Friday, 10 December 2010

recursive function for fibonaci series

//recursive for fib
#include<stdio.h>
#include<conio.h>
int fib(int n)
{
 static int a=0,b=1,c;
 if(n>0)
 {
  c=a+b;
  a=b;
  b=c;
  printf(" %d  ",c);
  fib(n-1);
  }
  return(0);
}
void main()
{
 int n;
 clrscr();
 int fib(int n);
 printf("enter the n value\n");
 scanf("%d",&n);
 printf("%d %d",0,1);
 fib(n);
 getch();
}

same program on iterative method: Program to print the Fibonacci series for 1 to n value
programs on recursive
recursive function

No comments:

Post a Comment