当前位置:网站首页>【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>
边栏推荐
- AcWing 607. Average 2 (implemented in C language)
- JS foundation 8
- Bisection (integer bisection and floating point bisection)
- Class pattern and syntax in JS 2021.11.10
- Database Series: is there any way to seamlessly upgrade the business tables of the database
- The default point of this in JS and how to modify it to 2021.11.09
- Which programming language will attract excellent talents?
- Batch will png . bmp . JPEG format pictures are converted to Jpg format picture
- Difference (one dimension)
- day25 js中的预解析、递归函数、事件 2021.09.16
猜你喜欢

Is it feasible to be a programmer at the age of 26?

day36 js笔记 ECMA6语法 2021.10.09

JS foundation 8

Convert black mask picture to color annotation file

QML控件类型:TabBar

day32 js笔记 事件(上)2021.09.27

Day31 JS notes DOM 2021.09.26
![Connectionreseterror: [winerror 10054] the remote host forced an existing connection to be closed](/img/9a/97813f5ac4d7c15711891cff25b9dd.jpg)
Connectionreseterror: [winerror 10054] the remote host forced an existing connection to be closed

day31 js笔记 DOM下 2021.09.26

js中的class类模式及语法 2021.11.10
随机推荐
Tidb v6.0.0 (DMR): initial test of cache table - tidb Book rush
多维度监控:智能监控的数据基础
AcWing 606. Average 1 (implemented in C language)
Still using simpledateformat for time formatting? Be careful that the project collapses!
day32 js笔记 事件(上)2021.09.27
Contract quantitative trading system development | contract quantitative app development (ready-made cases)
Simple understanding of ThreadLocal
MapReduce项目案例3——温度统计
On the output representation of bidirectional LSTM in pytoch
The default point of this in JS and how to modify it to 2021.11.09
Prefix and (one dimension)
js中this的默认指向及如何修改指向 2021.11.09
How to deploy the software testing environment?
js中的数组方法 2021.09.18
setInterval、setTimeout和requestAnimationFrame
Day36 JS notes ecma6 syntax 2021.10.09
Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community
5. Sum of N numbers
What is the main chain system?
Prepare for Jin San Yin Si I. testers without experience in automated testing projects should look at it quickly