function fb(i)
if i <= 2 and i > 0 then
return 1
else
local j = fb(i - 1) + fb(i - 2)
return j
end
end
i = 1
while i <= 20 do
print("想得到的斐波那的第"..i.. "个数是:"..fb(i))
i = i + 1
end
image.png
function fb(i)
if i <= 2 and i > 0 then
return 1
else
local j = fb(i - 1) + fb(i - 2)
return j
end
end
i = 1
while i <= 20 do
print("想得到的斐波那的第"..i.. "个数是:"..fb(i))
i = i + 1
end
image.png
本文标题:Lua练习9-斐波那数列
本文链接:https://www.haomeiwen.com/subject/aixbyktx.html
网友评论