Ques:C program to print fibonacci series of a given range using recursion [such that series last number will be less than or equal to given no.]
#include<stdio.h>
void fib(int ,int ,int );
int main()
{
int a=1, b=1, n;
printf("Enter the number");
scanf("%d",&n);
if(n==1)
printf("series is %d %d",(a-1),a);
else
{
printf("series is %d %d %d",(a-1),a,b);
fib(a,b,n);
}
return 0;
}
void fib(int a, int b, int n)
{
int temp;
if((a+b)<=n)
{
temp=a;
a=b;
b=a+temp;
printf("%d",b);
fib(a,b,n);
}
}
#include<stdio.h>
void fib(int ,int ,int );
int main()
{
int a=1, b=1, n;
printf("Enter the number");
scanf("%d",&n);
if(n==1)
printf("series is %d %d",(a-1),a);
else
{
printf("series is %d %d %d",(a-1),a,b);
fib(a,b,n);
}
return 0;
}
void fib(int a, int b, int n)
{
int temp;
if((a+b)<=n)
{
temp=a;
a=b;
b=a+temp;
printf("%d",b);
fib(a,b,n);
}
}
0 Comments