⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e419.m

📁 学习Matlab循环语句的好例子
💻 M
字号:
% 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -