斐波那契数列 1 1 2 3 5 8 13…
DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>循环语句title>
head>
<body>
<script type="text/javascript">
// 斐波那契数列 1 1 2 3 5 8 13......
var n = parseInt(window.prompt('input'));
if(n > 2){
var first = 1, second = 1, third;
for(var i = 0; i < n - 2; i ++){
third = first + second;
first = second;
second = third;
}
document.write(third);
}else{
document.write('请输入大于2的数');
}
script>
body>
html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)