Write a recursive function to generate n^{th} fibonacci term in C programming. How to generate n^{th} fibonacci term in C programming using recursion. Logic to find nth Fibonacci term using recursion in C programming.

**Example**

**Input**

Input any number: 10

**Output**

10th Fibonacci term: 55

## Required knowledge

Basic C programming, Function, Recursion

Must know - Program to generate Fibonacci series using for loop

## Declare recursive function to find nth Fibonacci term

- Assign a meaningful name to the function, say fibo().
- The function accepts an integer hence the function declaration is fibo(int num).
- Finally the function must return the n
^{th}Fibonacci term which is an integer.

Function declaration to find n^{th} Fibonacci term is - long long fibo(int num);

## Logic to find nth Fibonacci term using recursion

The recursive function to find n^{th} Fibonacci term is based on below three conditions.

- If num == 0 then return 0. Since Fibonacci of 0
^{th}term is 0. - If num == 1 then return 1. Since Fibonacci of 1
^{st}term is 1. - If num > 1 then return fibo(num - 1) + fibo(n-2). Since Fibonacci of any term is sum of previous two terms.

## Program to find nth Fibonacci term using recursion

```
/**
* C program to find nth Fibonacci term using recursion
*/
#include <stdio.h>
/* Function declaration */
long long fibo(int num);
int main()
{
int num;
long long fibonacci;
/* Input a number from user */
printf("Enter any number to find nth fiboacci term: ");
scanf("%d", &num);
fibonacci = fibo(num);
printf("%d fibonacci term is %lld", num, fibonacci);
return 0;
}
/**
* Recursive function to find nth Fibonacci term
*/
long long fibo(int num)
{
if(num == 0) //Base condition
return 0;
else if(num == 1) //Base condition
return 1;
else
return fibo(num-1) + fibo(num-2);
}
```

Output

Enter any number to find nth fiboacci term: 10 10 fibonacci term is 55

**Note:** Some compilers doesn't supports long long type so you must replace it with long and the format specifier with %ld to overcome the compilation error if any.

Happy coding 😉

<pre><code> ----Your Source Code---- </code></pre>