Home » Sometech » WAP to generate first n fibonacci terms using recursive function.

WAP to generate first n fibonacci terms using recursive function.

 

#include <stdio.h>

#include<conio.h>

long fib(int n);

void main()

{             

     int n,i;

     clrscr();

              printf(“\nHow many fibonacci terms you want to generate?\n”);

              scanf(“%d”,&n);

              printf(“First %d fibonacci terms are: \n “,n);

              for(i=1;i<=n;i++)

              printf(“%ld\t”,fib(i));

     getch();

}

 long fib(int n)

{

          if(n==1)

              return(0);

else

{

         if(n==2)

              return(1);

else

             return(fib(n-1)+fib(n-2));

 }

}

Advertisements

SoME Tech

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: