Thursday, November 22, 2012

C PROGRAM FOR FIBONNACCI USING RECURSION


/*C PROGRAM FOR FIBONNACCI USING RECURSION */

# include<stdio.h>
# include<conio.h>

void main()
{
 void fib(int);
          int n;
         clrscr();
         printf("\n\t\FIBONACCI USING RECURSION");
         printf("\n\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~");
         printf("\nEnter the number of terms : ");
         scanf("%d",&n);
         fib(n);
        getch();
 }

void fib(int d)
 {
 int i,t,a=0,b=1;
             if(d==1)
             {
             printf("%d",a); }

 else if (d==2)
 {
      printf("%d \t %d",a,b);
   }
 else
 {
       printf("%d \t %d",a,b);
       for(i=2;i<d;i++)
{
       t=a+b;
       printf("\t%d",t);
       a=b;
        b=t;
     }
   }
}






OUTPUT:

                FIBONACCI USING RECURSION
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter the number of terms: 6

0        1      1       2       3       5




0 comments:

Post a Comment