<函数-实现菲波那切数列>
作者:互联网
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
function sum(i) {
if ( i<=1 ) {
return 1;
}
return i+sum(i-1);
}
// 累加求和
document.write(sum(5));
document.write("<br>");
function ff(n) {
if( n==1 || n==2){
return 1;
}
return ff(n-2)+ff(n-1);
}
// for (var i=1; i<=5; i++) {
// sum+=ff(i);
// }
document.write(ff(5));
</script>
</body>
</html>
标签:function,return,数列,sum,那切,write,ff,菲波,document 来源: https://blog.csdn.net/weixin_45540964/article/details/110357248