For loop for fibonacci series
i am supposed to write a fibonacci series that calculate up to n term and (n-1) term but i am stuck at calculating the (n-1)term. can anyone help? ( i am new to matlab)
a = 0;
b = 1;
x = n-1;
n = input(‘Enter number of term desired’);
for i = 1:n %term for n
fprintf(‘t’)
fprintf(‘%d’,a);
c = a + b;
a = b;
b = c;
end
for i = n:x %term for n-1
fprintf(‘t’)
fprintf(‘%d’,a);
c = a + b;
a = b;
b = c;
endi am supposed to write a fibonacci series that calculate up to n term and (n-1) term but i am stuck at calculating the (n-1)term. can anyone help? ( i am new to matlab)
a = 0;
b = 1;
x = n-1;
n = input(‘Enter number of term desired’);
for i = 1:n %term for n
fprintf(‘t’)
fprintf(‘%d’,a);
c = a + b;
a = b;
b = c;
end
for i = n:x %term for n-1
fprintf(‘t’)
fprintf(‘%d’,a);
c = a + b;
a = b;
b = c;
end i am supposed to write a fibonacci series that calculate up to n term and (n-1) term but i am stuck at calculating the (n-1)term. can anyone help? ( i am new to matlab)
a = 0;
b = 1;
x = n-1;
n = input(‘Enter number of term desired’);
for i = 1:n %term for n
fprintf(‘t’)
fprintf(‘%d’,a);
c = a + b;
a = b;
b = c;
end
for i = n:x %term for n-1
fprintf(‘t’)
fprintf(‘%d’,a);
c = a + b;
a = b;
b = c;
end for loop MATLAB Answers — New Questions