WAP to print fibonacci series using recursion

#include<stdio.h>
#include<stdlib.h>

 int fibo(int,int,int);
 int main()
 {
 int n;
 printf("enter the value of n");
 scanf("%d",&n);
 printf("%d\t%d",1,1);
 fibo(n-2,1,1);
 printf("\n");
 system("PAUSE");
 }
 int fibo(int n,int old1,int old2)
 {
 int new;
 if(n==0)
 return;
 new=old1+old2;
 printf("\t%d",new);
 fibo(n-1,old2,new);
 }
method-2
 #include<stdlib.h>
 #include<stdio.h>
 int fibbo(int n1);
 int main()
 {
 int n,r,i;
 printf("enter the value of n");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
 r=fibbo(i);
 printf("%d",r);
 }
 system("PAUSE");
 }
 int fibbo(int n1)
 {
 if(n1<1)
 return(0);
 if(n1==1)
 return(1);
 else
 return(fibbo(n1-1)+fibbo(n1-2));
 }
Advertisements

Leave a comment

Filed under TUTORIALS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s