Problem 12. Fibonacci sequence
Calculate the nth Fibonacci number.
Given n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 2, ...
Examples:
Input n = 5
Output f is 5
Input n = 7
Output f is 13
Solution Stats
Problem Comments
-
22 Comments
Show
19 older comments
Miron Krejci
on 5 Mar 2024
Good one
William Katzianer
on 6 Feb 2025
@Christian you still can do it without if/else chains. Just create a lookup table of fibonacci answers and then pull n+1 from the sequence. No if/else required
Jason
on 10 Mar 2025 at 15:11
The first Fibonacci number is 0, not 1.
Solution Comments
Show commentsGroup

Programování - Cody
- 12 Problems
- 466 Finishers
- Find the sum of all the numbers of the input vector
- Maximum value in a matrix
- Make the vector [1 2 3 4 5 6 7 8 9 10]
- Return area of square
- Select every other element of a vector
- Triangle Numbers
- Check if number exists in vector
- Create times-tables
- Determine whether a vector is monotonically increasing
- Roll the Dice!
- Verify Law of Large Numbers
- Solve a System of Linear Equations
Problem Recent Solvers13577
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!