Menu
Coddy logo textTech

Fibonacci Sequence

Lesson 1 of 15 in Coddy's Recursion Challenges - Master The Recursive Thinking course.

The Fibonacci sequence starts from 0, 1 and each element is the sum of the previous 2 elements.

The sequence - 0, 1, 1, 2, 3, 5, 8, 13, 21, ....

For example, the 6th element is 8 because 3 + 5 = 8 (sum of the previous 2 elements)

challenge icon

Challenge

Easy

Write a function named fibo that gets an integer i and returns the ith element in the Fibonacci sequence.

As declared 0th element is 0 and 1th element is 1

Make sure to do it with recursion!

Try it yourself

int fibo(int i) {
    // Write code here
    return 0;
}

All lessons in Recursion Challenges - Master The Recursive Thinking