The Fibonacci numbers is a sequence of numbers Fi:
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:10| Question number:26.10
All Answers
total answers (1)
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:10| Question number:26.10
total answers (1)
fib.m
function outval = fib(n)
% Recursively calculates the nth Fibonacci number
% Format of call: fib(n)
% Returns the nth Fibonacci number
if n == 0
outval = 0;
elseif n == 1
outval = 1;
else
outval = fib(n-2) + fib(n-1);
end
end
>> for i = 1:20
fprintf('%d\n', fib(i))
end
need an explanation for this answer? contact us directly to get an explanation for this answer