C program to Fibonacci by Recursion

Below is C program to Fibonacci by Recursion .

Program:

/* Fibonacci by Recursion */

#include<stdio.h>
int fib(int);

int main()
{
 printf("Type any value : ");
 printf("\nNth value: %d",fib(getche()-'0'));
 return 0;
}

int fib(int n)
{
 if(n<=1)
  return n;
 return(fib(n-1)+fib(n-2));
}

No comments:

Post a Comment