当前位置:网站首页>【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>
边栏推荐
- Apache2配置对目录拒绝访问,但是可以访问里面文件的设置
- [sciter]: use of sciter FS module scanning file API and its details
- NFT card chain game system development DAPP construction technical details
- 【无标题】虚拟机vmnet0找不到且报错:没有未桥接的主机网络适配器
- ProCAST finite element casting process simulation software
- Daily practice of C language - day 4: find the sum of all even numbers within 100
- day39 原型鏈及頁面烟花效果 2021.10.13
- 赛尔号抽奖模拟求期望
- Allez, Meta - Cosme, comme prévu, cette chaleur ne durera pas longtemps.
- MapReduce项目案例1
猜你喜欢
Data analysis learning notes
2022中国信通院首届业务与应用安全发展论坛成功召开!
Share the easy-to-use fastadmin open source system - practical part
Join hands with cigent: group alliance introduces advanced network security protection features for SSD master firmware
For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?
Swin, three degrees! Eth open source VRT: a transformer that refreshes multi domain indicators of video restoration
QML control type: tabbar
Necessary for beginners PR 2021 quick start tutorial, PR green screen matting operation method
Unity screenshot function
《运营之光3.0》全新上市——跨越时代,自我颠覆的诚意之作!
随机推荐
Share the easy-to-use fastadmin open source system - practical part
Still using simpledateformat for time formatting? Be careful that the project collapses!
day34 js笔记 正则表达式 2021.09.29
Deployment and optimization of vsftpd service
Django -- MySQL database reflects the mapping data model to models
day29 js笔记 2021.09.23
day32 js笔记 事件(上)2021.09.27
Remote login sshd service
Web3 security serials (3) | in depth disclosure of NFT fishing process and prevention techniques
人人都可以参与开源!龙蜥社区最不容错过的开发者活动来了
Prefix and (one dimension)
AcWing 606. Average 1 (implemented in C language)
建立自己的网站(18)
MapReduce项目案例1
FTP protocol for Wireshark packet capture analysis
JS foundation 10
Array method in JS 2021.09.18
Simple understanding of ThreadLocal
《运营之光3.0》全新上市——跨越时代,自我颠覆的诚意之作!
day39 原型链及页面烟花效果 2021.10.13