Skip to content
Home » C Programs » Fibonacci Program in C Using Recursion

Fibonacci Program in C Using Recursion

Simple fibonacci program in c using recursion for beginners to understand how to implement the fibonacci program in c for beginners in programming language.

Definition of Fibonacci Series

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 Definition in C

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 Statement 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. Using this method we can execute the fibonacci program in c using recursion.

Else If Statement in C

In C, the if-else statement is used to carry out operations based on a set of conditions. If and only if the supplied condition is true, the operations stated in the if block are executed. 

You can create a chain of if statements using the if/else if statement. The if statements are evaluated one after the other until one of the if expressions is true or the if/else if chain ends. If there is no true expression at the end of the if/else if chain, no code blocks are executed. This is main concept for the program like this fibonacci program in c using recursion.

Fibonacci Program in C Using Recursion

//fibonacci program in c using recursion 
int fib(int);
int main()
int n, i; 
printf("Enter the number\n"); 
printf("fib series is \n");
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 of fibonacci program in c using recursion:

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