Saturday, 20 February 2016

C Program To Find The Nth Fibonacci Number Using Recursion Problem Solution.


Solution:

#include <stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
long long fib(long long a,long long b,int n){
 if(n == 0)return a;
 else return fib(b,a+b,n-1);
}
int main(void) {

 int n;
 scanf("%d",&n);
 if(n > 90)printf("Input number is to big.\n");
 else printf("The %d number in fibonacci series is: %lld\n",n,fib(0,1,n));
 return 0;
}

No comments:

Post a Comment