Program to compute a specified Fibonacci number using recursion in C

 #include <stdio.h>
 
 int fib(int);
 
 int main()
 {
    int n;
 
    printf("Enter the value : ");
    scanf("%d",&n);
    printf("nFib(%d) = %dn",n,fib(n));
    return 0;
 }
 
 int fib(int n)
 {
    if(n > 2)
        return (fib(n-1) + fib(n-2));
    else
        return 1;
 }

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.