e419.m
来自「学习Matlab循环语句的好例子」· M 代码 · 共 31 行
M
31 行
% Script file: Fibonacci.m
% Purpose:
% To calculate any order's Fibonacci number,n is inputed by user
% the output is the value of Fibonacci number
% Record of revisions:
% Date Programmer Description of change
% ========== ============ ==========================
% 06/06/08 ZMW Original code
% Define variables
% n ------------ nth Fibonacci
% f ------------ nth Fibonacci's value array
% ii -----------index
n=input('Please Enter the order n:');
while n<2
disp('Please reEnter the order n(n>2):');
n=input('Please Enter the order n:');
end
f=zeros(1,n);
f(1)=1;
f(2)=2;
ii=3;
while ii<=n
f(ii)=f(ii-1)+f(ii-2);
ii=ii+1;
end
fprintf('The Value of nth Fibonacci is : %d\n',f(n));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?