主题:兔子数列
qbasic爱好者
[专家分:10] 发布于 2009-08-09 18:07:00
50分悬赏
回复列表 (共4个回复)
沙发
phile [专家分:2310] 发布于 2009-08-09 20:08:00
请问啥意思!
板凳
1054122 [专家分:750] 发布于 2009-08-10 11:54:00
是斐波那锲数列吗?如果是的话:
CLS
INPUT "Da yin dao : ", n
LET a = 1
LET b = 1
PRINT a; b;
FOR i = 3 TO n
LET c = a + b
PRINT c;
LET a = b
LET b = c
NEXT i
END
3 楼
梦幻小樱 [专家分:140] 发布于 2009-08-10 16:51:00
CLS
INPUT "Da yin dao : ", n
LET a = 1
LET b = 1
PRINT a; b;
FOR i = 3 TO n
LET c = a + b
PRINT c;
LET a = b
LET b = c
NEXT i
END
4 楼
phile [专家分:2310] 发布于 2009-08-10 17:22:00
如果是斐波那契的话,那给程序
(转帖)
方法一(普通算法):
CLS
INPUT n
DIM a(n)
a(1) = 1: a(2) = 1
FOR i = 3 TO n
a(i) = a(i - 1) + a(i - 2)
NEXT i
PRINT a(n)
END
方法2(递归算法):
cls
input n
print fib(n)
end
function fib(x)
if n=1 then
fib=1
else
if n=2 then
fib=2
else
fib=fib(n-1)+fib(n-2)
endif
end function
方法3(高精度):
CLS
INPUT "n=", n
DIM a(200), b(200), c(201), s(201)
a(1) = 1
b(1) = 1
s(1) = 2
FOR i = 3 TO n
jw = 0
FOR j = 1 TO 200
c(j) = a(j) + b(j) + jw
jw = c(j) \ 10
c(j) = c(j) MOD 10
NEXT
FOR j = 1 TO 200
a(j) = b(j)
b(j) = c(j)
NEXT
NEXT
i = 201
DO WHILE c(i) = 0
i = i - 1
LOOP
y = 201
DO WHILE s(y) = 0
y = y - 1
LOOP
PRINT "di n xiang wei:";
FOR j = i TO 1 STEP -1
PRINT USING "#"; c(j);
NEXT
PRINT
我来回复