Info

This question is closed. Reopen it to edit or answer.

Fibonacci Series in cody Challenge

1 view (last 30 days)
NAVNEET NAYAN
NAVNEET NAYAN on 30 Jul 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
I am solving Fibonacci series in Cody challenge. I have written the following code and it is running well in MATLAB editor. here is the code
function f = fib(n)
if (n>2)
f(1)=1;
f(2)=1;
for i=3:n
f(i)=f(i-1)+f(i-2);
end
elseif n==2
f(1)=1;
f(2)=1;
elseif (n==1)
f(1)=1;
else
disp('invalid input')
end
end
However when I am submitting it in cody incorrect answer is displayed. Can anyone suggest it why this one is running in editor and wrong when submitted?
  2 Comments
NAVNEET NAYAN
NAVNEET NAYAN on 31 Jul 2018
Yes, you are right. They wanted only last number. I was trying too much.
Thanks

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!