Friday, September 30, 2011

Computing Fibonacci Numbers via Binary Recursion

This C++ code will allow you to find the kth term in Fibonacci Series
Just compile it and you will have the results



#include
using std::cout;
using std::cin;
using std::endl;

int fibb(int);

int main()
{
    int k;
    cout << "Please enter the kth element to calculate: " << endl;
    cin >> k;
    cout << "The kth element is " << endl <}

int fibb(int kthElement)
{
    if(kthElement <= 1)               // the base case
        return kthElement;
    return fibb(kthElement - 1) + fibb(kthElement - 2);  // The recursion function
}



Please rate this topic


If you like this topic please support by downloading this file
Download To Suppport


No comments:

Post a Comment