SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
C Program to print Nth Fibonacci Number
C Program to print Nth Fibonacci Number
Input:
5
Output:
8
#include
#include
/* function to find nth fibonacci number */ int findnthfibo(int n) { /* break the recursive call if value of n reaches 0*/ if(n==0) return 1; /* break the recursive call if value of n reaches 1 either */ if(n==1) return 1; /* in other cases, call the function findnthfibo recursively to return the nth fibonacci number */ return findnthfibo(n-1)+findnthfibo(n-2); } int main(void) { int n; /* get the number to print the fibonacci number of nth number */ scanf("%d",&n); /* call the recursive function 'findnthfibo' to find the nth fibonacci number */ printf("%d-fibonacci number is %d",n,findnthfibo(n)); return 0; }
PREVIOUS
NEXT
HOME