I broke Cody server with this.
function f = fib(n)
a=[0 1];
indx=n-1;
if n==0
f=a(1);
elseif n==1
f=a(2);
else
while indx <= n
a(indx+1)=fib(n-1)+fib(n-2);
indx=indx+1;
end
f=a(n);
end
also my size is -1 shouldnt I win?
When you want to calculate fib(1), it calls fib(0) + fib(-1). There is no fib(-1) so you never leave the while loop.
962 Solvers
6283 Solvers
Back to basics 13 - Input variables
233 Solvers
387 Solvers
413 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!