Friday 23 September 2016

Fibonacci by Recursion

/* 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

Featured post

The Thrill of Programming: Exploring the Satisfaction Behind the Code

Different individuals find satisfaction in programming for various reasons. Here are some common factors that tend to bring satisfaction to ...