菲薄数列

/**
* Created by wangchaomac on 2017/3/13.
*/
/*
1.斐波那契数列
**/
function fbnq(sqIndex){
var firstNo = 1;
var secondNo = 1;
if( sqIndex < 2 ) {
if( sqIndex < 0) {

return 'error input param';
}
return 1;
}

var fbnqNo = -1;

for(var fbnqIndex = 2; fbnqIndex < sqIndex ; fbnqIndex ++) {

fbnqNo = firstNo + secondNo ;
firstNo = secondNo ;
secondNo = fbnqNo ;
}

return fbnqNo;

}
alert(fbnq(4));
posted @ 2017-03-13 11:24  小毛驴  阅读(380)  评论(0编辑  收藏  举报