C Program To Find nth Fibonacci Number Using Recursion
Write a C progrm to find nth Fibonacci number using recursion. This C program find the nth term in fibonacci series using recursive function.
C Program :
/* Aim: Write a recurssive function to find nth fibonacci number */ #include<stdio.h> int fibonacci(int n); // Function Prototype void main() { int n,i; printf("\n Which term do you want to find:- "); scanf("%d",&n); printf("\n %d term of fibonacci sequence is %d \n \n",n,fibonacci(n)); } // fibonacci Function int fibonacci(int n) { if (n==1 || n== 2) return 1; else return( fibonacci(n-2) + fibonacci(n-1)); }
/* Output of above code:-
[root@localhost ~]# cc fibonacci.c
[root@localhost ~]# ./a.out
Which term do you want to find:- 4
4 term of fibonacci sequence is 3
*/
Comments