Question

CH Question 1. Implement a recursive method fibo that takes an integer num as a parameter and returns the nth Fibonacci numbe
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

// recursive method to find the nth fibonacci number

// input is the number n

// output is the nth fibonacci number

int fibo(int n) {

    // base case

    if (n == 1 || n == 2) {

        return 1;

    }

    // recursive call

    return (fibo(n-1) + fibo(n-2));

}


// mult function to return the multiplication of two numbers using recursion

// input is two integers

// output is product of two input numbers

int mult(int a, int b) {

    // base case

    if (b == 0) {

        return 0;

    }

    // recursive call

    return a + mult(a, b-1);

}


// main function

int main() {

    // test input

    int n = 6;

    int a = 3, b = 5;

    // display the results and test calls

    cout << n << "th fibonacci number: " << fibo(n) << endl;

    cout << a << " * " << b << " = " << mult(a, b) << endl;

    return 0;

}

- /main 6th fibonacci number: 8 3 + 5 = 15

for help please comment.
thank you.

Add a comment
Know the answer?
Add Answer to:
CH Question 1. Implement a recursive method fibo that takes an integer num as a parameter...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT