Fibonacci numbers are the numbers in a sequence in which the first two elements
ID: 3816896 • Letter: F
Question
Fibonacci numbers are the numbers in a sequence in which the first two elements are 0 and 1. and each subsequent element is the sum of the previous two elements 0, 1, 1, 2, 3, 5, 8, 13, ... Use for-loops, comment your code Write a script file that calculates and displays the first 15 Fibonacci numbers Only use scalars, i.e. NO arrays, in your for loop Write a script file that calculates and displays the first 15 Fibonacci numbers Inside your loop, store all elements of the sequence in a vector array. Inscribe the main advantage(s) of using arrays in loops (instead of just scalars) Fibonacci numbers are the numbers in a sequence in which the first two elements are 0 and I, and each subsequent element is the sum of the previous two elements 0, 1, 1, 2, 3, 5, 8, 13, ... Use indexed while-loops to prevent infinite loops, comment your code. Write a script file that calculates and displays all Fibonacci numbers below 1000 Only use scalars, i.e. NO airways in you for loop Write a script file that calculates and displays all Fibonacci numbers below 1000. Inside Could you have solved the problem as stated using for-loops? ExplainExplanation / Answer
N=15;
fib=zeros(1,N);
fib(1)=1;
fib(2)=1;
k=3;
while k <= N
fib(k)=fib(k-2)+fib(k-1);
k=k+1;
end
fprintf('The Fibonacci sequence to %d terms is ',N);
fprintf('%g ',fib);
fprintf(' ');
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.