当前位置:网站首页>【JS】斐波那契数列实现(递归与循环)
【JS】斐波那契数列实现(递归与循环)
2022-06-28 11:36:00 【贾璞】
斐波那契数列实现【递归与循环】
1.循环
<script>
var line = parseInt(prompt("input lines:"));
var a = 1,
b = 1;
for (var i = 0; i < line / 2; i++) {
document.write(a + "</br>", b + "</br>");
a = a + b;
b = b + a;
}
</script>
2.递归
<script>
function fabio(line) {
if (line == 1 || line == 2)
return 1;
else
return fabio(line - 1) + fabio(line - 2);
}
var line = parseInt(prompt("input lines:"));
for (var i = 1; i <= line; i++) {
if (i < line)
document.write(fabio(i) + '</br>');
else
document.write(fabio(i));
}
</script>
边栏推荐
- QML control type: tabbar
- What method is required for word, PDF and txt files to realize full-text content retrieval?
- Deployment and optimization of vsftpd service
- Data analysis learning notes
- mysql-. SQL file phishing Online
- day39 原型链及页面烟花效果 2021.10.13
- [sciter]:sciter如何使用i18实现桌面应用多语言切换及其利弊
- 多维度监控:智能监控的数据基础
- Analyze whether there is duplicate data in the list and repeat it several times
- Open3d manual clipping point cloud
猜你喜欢

人人都可以参与开源!龙蜥社区最不容错过的开发者活动来了

Industry analysis - quick intercom, building intercom

Why do many people want to change careers as programmers, while some programmers want to change careers as others?

Jetpack Compose Desktop 桌面版本的打包和发布应用

Tidb v6.0.0 (DMR): initial test of cache table - tidb Book rush

js中this的默认指向及如何修改指向 2021.11.09

The default point of this in JS and how to modify it to 2021.11.09

Convert black mask picture to color annotation file

Simulation of the Saier lottery to seek expectation

day32 js笔记 事件(上)2021.09.27
随机推荐
AGCO AI frontier promotion (2.16)
SoapUI rookie tutorial
Characteristics of solar wireless LED display
Self use demo of basic component integration of fluent
人人都可以参与开源!龙蜥社区最不容错过的开发者活动来了
AcWing 608. Poor (implemented in C language)
2018 joint examination of nine provinces & Merging of line segment trees
Fruit FL studio/cubase/studio one music host software comparison
Day34 JS notes regular expression 2021.09.29
Training notice | special training notice on epidemic prevention and security prevention for overseas Chinese funded enterprises, institutions and personnel in 2022
[sciter]: use of sciter FS module scanning file API and its details
fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)
[no title] the virtual machine vmnet0 cannot be found and an error is reported: there is no un bridged host network adapter
Data analysis learning notes
Excel import / export convenience tool class
Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community
Class pattern and syntax in JS 2021.11.10
来吧元宇宙,果然这热度一时半会儿过不去了
Mysql使用max函数查询不到最大值
NFT card chain game system development DAPP construction technical details