Q. Write a C program to generate Fibonacci series using recursion method.
Ans.
/*c program to generate Fibonacci series using recursion method*/
#include<stdio.h>
#include<conio.h>
int fibo(int , int ); /*declaration function*/
int main()
{
int num=1,previous_num=0;
printf("Fibonacci Series first 30 elements: ");
printf("\n\n\t1");
fibo(previous_num,num); /*calling function*/
getch();
return 0;
}
fibo(int prev, int n) /*definition of function*/
{
static int r=1;
int series;
if(r!=30)
{
series=prev+n;
prev=n;
n=series;
printf("\n\t%d",series);
r++;
fibo(prev,n);
}
}
/************Output************/
Related Programs:
or
Q. Write a C program to accept any number from user and create its equal-ant Fibonacci series using recursion method.Ans.
/*c program to generate Fibonacci series using recursion method*/
#include<stdio.h>
#include<conio.h>
int fibo(int , int ); /*declaration function*/
int main()
{
int num=1,previous_num=0;
printf("Fibonacci Series first 30 elements: ");
printf("\n\n\t1");
fibo(previous_num,num); /*calling function*/
getch();
return 0;
}
fibo(int prev, int n) /*definition of function*/
{
static int r=1;
int series;
if(r!=30)
{
series=prev+n;
prev=n;
n=series;
printf("\n\t%d",series);
r++;
fibo(prev,n);
}
}
/************Output************/
Figure: Screen shot for Generate Fibonacci series to a specific range using recursion method C program |
Related Programs:
No comments:
Post a Comment