Header Ads Widget

Program to print the Fibonacci series by using recursion.

Program to print the Fibonacci series by using recursion:

Here in this article we will write a program to print the fibonacci series . So first we have to know that what is fibonacci series  . 

Fibonacci series :-
The Fibonacci sequence is a series of numbers in which each number is the sum of the two previous number . It start with 0 and 1 .  

Program to print the Fibonacci series by using recursion:

The Objective of code is to print the fibonacci series by using recursion . In Fibonacci series each element is the sum of it's two previous elements. If we want to print nth element then it is sum of (n-1)th and (n-2)th terms . 


program:-
#include<stdio.h>
int fib(int n)
{
if(n==1||n==2)
return 1;
return (fib(n-1)+fib(n-2));
}
int main()
{
int n,i;
printf("Enter number of term in fibbo series");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d ",fib(i));
}
return 0;
}

 

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

 

Post a Comment

0 Comments