Can anyone suggest how to reduce the size of the code ?
Yes there are 2 ways. You can initialise f1 as a vector [1, 1]. You also don't need the if else statement if you use start i = 1:n and then use f1(i+2) = ...
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
n = 1;
f = 1;
assert(isequal(fib(n),f))
|
2 | Pass |
%%
n = 6;
f = 8;
assert(isequal(fib(n),f))
|
3 | Pass |
%%
n = 10;
f = 55;
assert(isequal(fib(n),f))
|
4 | Pass |
%%
n = 20;
f = 6765;
assert(isequal(fib(n),f))
|
Arrange vector in ascending order
624 Solvers
420 Solvers
Right Triangle Side Lengths (Inspired by Project Euler Problem 39)
511 Solvers
Find out missing number from a vector of 9 elements
245 Solvers
Is this is a Tic Tac Toe X Win?
438 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!