著名的斐波那契數列

靚仔寧發表於2020-12-13

1 1 2 3 5 8 輸出第n 項

var n = parseInt(window.prompt("imput"));

var first = 1;

       second = 1;

       third;

if (n > 2) {

   for(var i = 0; i< n-2; i++){

    third  = first + second ;

    first = second;

    second = third;

docunment.write(third);

 

} else {

  document.write(1)

}

}

相關文章