MATLAB Answers

'Store the first N (user enters N) Fibonacci numbers in a row vector.'I know how to get user entered number of fibbonachi numbers. But I don't know how to show them in a row vector.

1 view (last 30 days)
clc;
clear;
close all;
N=input('Enter the number = ');
B(1)=0;
B(2)=1;
count=1;
for i=3:N
B(1,i)=B(i-2)+B(i-1);
end
disp(B)

  0 Comments

Sign in to comment.

Accepted Answer

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH on 7 Dec 2019
clc
N=input('Enter the number = ');
B=zeros(1,N);
B(1)=0;
B(2)=1;
count=1;
for i=3:N
B(1,i)=B(i-2)+B(i-1);
end
disp(B)

  3 Comments

Lakshan Bandara
Lakshan Bandara on 7 Dec 2019
Enter the number = 10
0 1
0 0
1 0
1 0
2 0
3 0
5 0
8 0
13 0
21 0
Answer comes like this. Is there any way to get rid of the second row.
JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH on 7 Dec 2019
yes but I get:
Enter the number = 10
0 1 1 2 3 5 8 13 21 34
in any case, to get rid of the second column use:
B(:,2)=[]

Sign in to comment.

More Answers (0)

Sign in to answer this question.