Fibonacci sequence recursive function algorithm question.

Asked 2 years ago, Updated 2 years ago, 81 views

The Fibonacci sequence has a repetition that the sum of the total number and the total number is the next number, like 11 2 3 5 8 13, which is how this is coded as a recursive function

int Fib(int n)
{
    if (n == 0)
        return 0;
    else if (n == 1)
        return 1;
    else
        return Fib(n-1) + Fib(n-2);
}

I don't understand if it's like this. It's not that I didn't understand the ambiguity at all, but the level of understanding is very strong.

Should we understand that the reason why returnFib(n-1) + Fib(n-2); comes out is simply because the sum of all numbers and all numbers is repeated, so (n-1) and (n-2) are recursive?

And is there a way to understand recursive functions more intuitively?

c fibonacci recursion

2022-09-20 11:02

1 Answers

I just started learning this programming language and already realized that there's nowhere without math. I need more basic math skills here https://kr-casinos.com/casino-bonuses/ that I use to play reviews on this site. Now I realize that I still need to urgently watch a series of lectures on computing, separate hello in the world, afterwards, I haven't been able to make it yet


2022-09-20 11:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.