Below is C program to Fibonacci by Recursion .
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /* 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