Custom MA TLAB function and While Loop problem Write a MATLA
Custom MA TLAB function and While Loop problem Write a MATLAB function called LFibN_Name with 1 input (Lim) and 1 The input (Lim) is less than or equal to the last element of the Fibonacci Sequence, the output (Nfib) is the number of elements of the Fibonacci Sequence. For example. if lim = 5, then Nfib = 6 F = [0 1 1 2 3 S] has 6 elements since the last element 5
Solution
function [ Nfib ] = LFibN_Name(lim )
if lim>=1
a=0;
b=1;
c=1;
Nfib=2;
while c<=lim
c=a+b;
a=b;
b=c;
if(c<=lim)
Nfib=Nfib+1;
end
end
end
end
