Fibonacci Series Program in C Using Recursion

Fibonacci series program in c using recursion method for beginners to understand how to implement the Fibonacci series method using recursion.

Fibonacci Series Program in C Using Recursion

One of the most well-known mathematical formulas is the Fibonacci sequence. The sum of the two numbers before it determines the next number in the sequence. 

Fibonacci levels are employed as indicators of probable trade development. Prior to acting on the Fibonacci level, the price must confirm. Traders have no idea which level will be crucial ahead of time, so they must wait and watch which level the price respects before entering a trade.

Recursion Method in C Program

The Fibonacci sequence’s recursive formula describes the first two terms and defines each subsequent term as the sum of the two terms before it. a1=1a2=1an=an−1+an−2,forn≥3. For example, to find the tenth term of the sequence, we would sum the eighth and ninth terms.

If Else Definition in C

If else is a conditional statement in programming that executes a separate series of statements based on whether an expression is true or false. The test expression inside the parenthesis () is evaluated by the if statement. 

If the test expression returns true, the statements in the if body are performed. Statements inside the body of if are not performed if the test expression is evaluated to false.

#include<stdio.h>
int fib(int);
int main()
{ 
int n, i; 
printf("Enter the number\n"); 
scanf("%d",&n); 
printf("fib series is \n");
for(i=0;i<n;i++) 
{ 
printf("%d ",fib(i));
}
}

int fib(int i)
{ 
if(i==0) return 0; 
else if(i==1) return 1; 
else return (fib(i-1)+fib(i-2));
} 

Output:

Enter the number
10
fib series is
0 1 1 2 3 5 8 13 21 34