主题:急需杨辉三角的简单编程
张扬SKY
[专家分:20] 发布于 2007-08-20 22:37:00
急需详细的杨辉三角编程啊!尤其是打印时的格式!!!
打印格式的顺序啊!!!
先谢谢各位的提点啊!!!
回复列表 (共3个回复)
沙发
wzc1996 [专家分:1680] 发布于 2007-08-21 13:02:00
CLS
INPUT n
DIM a(n, n)
a(1, 1) = 1
FOR i = 2 TO n
a(i, 1) = 1:a(i, i) = 1
FOR j = 2 TO i - 1
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
NEXT j
NEXT i
FOR i = 1 TO n: PRINT TAB(40 - 3 * i);
FOR j = 1 TO i
PRINT USING "######"; a(i, j);
NEXT j
PRINT
NEXT i
板凳
Matodied [专家分:7560] 发布于 2007-08-21 13:55:00
可以用一维数组。
CLS
INPUT n
DIM a(n + 1), b(n + 1)
a(1) = 1
FOR i = 1 TO n
PRINT TAB(35 - i * 3);
FOR j = 1 TO i
PRINT LTRIM$(STR$(a(j))); " ";
IF j = 1 THEN b(j) = 1 ELSE b(j) = a(j) + a(j - 1)
NEXT j: PRINT : b(i + 1) = 1
FOR j = 1 TO i + 1: a(j) = b(j): NEXT j
NEXT i
3 楼
小小傻瓜 [专家分:150] 发布于 2007-08-21 17:42:00
CLS
INPUT n
DIM a(n, n)
a(0, 1) = 1
FOR i = 1 TO n
FOR j = 1 TO i
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
NEXT j
NEXT i
FOR i = 1 TO n
PRINT TAB(40 - 3 * i);
FOR j = 1 TO i:PRINT USING "######"; a(i, j);:NEXTj
PRINT
NEXT i
我来回复