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
-
21 Comments
Show
18 older comments
Christian Schröder
on 20 Nov 2023
@Brendan It's most likely an attempt to make look-up solutions that merely encode the return values for all the tests (and which are widely considered cheating) that little bit harder. I do agree that this is questionable insofar as that banning elseif in particular also messes with genuine solutions.
Miron Krejci
on 5 Mar 2024
Good one
William Katzianer
on 6 Feb 2025 at 14:45
@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
Solution Comments
Show commentsProblem Recent Solvers13570
Suggested Problems
-
4116 Solvers
-
3247 Solvers
-
1739 Solvers
-
580 Solvers
-
600 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!