GoogelAddUnit1

Thursday, 10 March 2011

C Program on fibonacci suing Recursion.?

/* Fibonacci series using recursion */                 
#include<stdio.h>
#include<conio.h>
int a=0,b=1,c;
main()
{
   int n,k;
   clrscr();
   printf("\n enter the value of n");
   scanf("%d",&n);
   printf("\n %d %d",a,b);
   fib(n,a,b);
   getch();
}
fib(int n,int a,int b)
{
    int c,i=2;
    while(i<n)
    {
      c=a+b;
      printf("  %d",c);
      a=b;
      b=c;
      i++;
      return fib(n-1,a,b);
    }
}

No comments:

Post a Comment