0
993views
What is recursion? Write a program to compute Fibonacci series using recursion.

Mumbai University> FE > Sem 2> STRUCTURED PROGRAMMING APPROACH

Marks: 5 M

Year: Dec 2016

1 Answer
0
1views

Recursion:

In C, it is possible for the functions to call themselves. A function is called 'recursive' if a statement within the body of a function calls the same function. Sometimes called 'circular definition', recursion is thus the process of defining something in terms of itself.

Program:

#include<stdio.h>
#include<conio.h>
void fibo(int n);
main()
{
int n;
clrscr();
printf("Enter range ");
scanf("%d",&n);
printf("\n0  1  ");
fibo(n);
getch();
}


void fibo(int n)
{
static int a=0,b=1,c;

if(n>2)
{
c=a+b;
a=b;
b=c;
printf("%d  ",c);
fibo(n-1);
}
}
output:
0   1   1   2   3   5   8   13  21  34
Please log in to add an answer.

Continue reading...

The best way to discover useful content is by searching it.

Search