var ct = 0; //成兔對數
var xt = 0; //小兔對數
var yt = 1; //幼兔對數
var zt = 1; //總兔對數
for (i = 1; i <= 8; i++) { if (i == 1) //第一個月的成兔幼兔小兔對數 { ct = 0; //第一個月的成兔對數是0對
xt = 0; //第一個月的小兔對數是0對
yt = 1; //第一個月的幼兔對數是1對
} else { ct = xt + ct; //每月成兔對數等于上月小兔對數加上月成兔對數
xt = yt; //本月小兔對數等于上月幼兔對數
yt = ct; //本月幼兔對數等于上月成兔對數
} } console.log("8個月后成兔對數是:" + ct); //8 console.log("8個月后小兔對數是:" + xt); //5 console.log("8個月后幼兔對數是:" + yt); //8 zt = ct + xt + yt; console.log("8個月后總兔對數是:" + zt); //21
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/98441.html
標籤:JavaScript
