i) Write a program to generate Fibonacci series using recursion. ii) Write a program to find GCD of two numbers using recursion.

Leave a Comment
i) Write a program to generate Fibonacci series using recursion.
ii) Write a program to find GCD of two numbers using recursion.

#include<sdtio.h>
#include<conio.h>
void fibo(int a,int b,int n)
{
int t;
if(n==0)
return;
else
{
t=a+b;
a=b;
b=t;
n--;
printf("%d\t",t);
return fibo(a,b,n);
}
}
int gcd(int n,int m)
{
while(n!=m)
{
if(n>m)
return gcd(n-m,m);
else
return gcd(n,m-n);
}
return n;
}
int main()
{
int n,m;
printf("\nEnter the max limit for fibo:");
scanf("%d",&n);
printf("\nThe fibonacci series as follows\n0\t1\t");
fibo(0,1,n-2);

printf("\nEnter the number u wanna find the GCD of:");
scanf("%d%d",&n,&m);
printf("\nThe GCD of %d & %d is %d",n,m,gcd(n,m));

getche();
}

0 comments: