主题:编程求解
冰冻小企鹅
[专家分:190] 发布于 2009-02-09 10:10:00
编程打印数字菱形,将由键盘输入的1—9之间的自然数作为菱形最外层的数(如下图)
5
545
54345
5432345
543212345
5432345
54345
545
5
这道题简单 [em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11][em11]
回复列表 (共6个回复)
沙发
1054122 [专家分:750] 发布于 2009-02-13 21:41:00
CLS
FOR i = 1 TO 5
PRINT SPC(5 - i);
FOR j = 1 TO 2 * i - 1
IF j = 1 OR j = 2 * i - 1 THEN
PRINT "5";
ELSEIF j = 2 OR j = 2 * (i - 1) THEN
PRINT "4";
ELSEIF j = 3 OR j = 2 * (i - 2) + 1 THEN
PRINT "3";
ELSEIF j = 4 OR j = 2 * (i - 2) THEN
PRINT "2";
ELSE
PRINT "1";
END IF
NEXT j
PRINT
NEXT i
FOR i = 4 TO 1 STEP -1
PRINT SPC(5 - i);
FOR j = 1 TO 2 * i - 1
IF j = 1 OR j = 2 * i - 1 THEN
PRINT "5";
ELSEIF j = 2 OR j = 2 * (i - 1) THEN
PRINT "4";
ELSEIF j = 3 OR j = 2 * (i - 2) + 1 THEN
PRINT "3";
ELSEIF j = 4 OR j = 2 * (i - 2) THEN
PRINT "2";
ELSE
PRINT "1";
END IF
NEXT j
PRINT
NEXT i
END
板凳
hxy_anhui [专家分:320] 发布于 2009-02-14 19:52:00
CLS
INPUT N
FOR I = -(N - 1) TO N - 1
PRINT TAB(ABS(I) + 1);
FOR J = N TO ABS(I) + 1 STEP -1
PRINT LTRIM$(STR$(J));
NEXT J
FOR J = ABS(I) + 2 TO N
PRINT LTRIM$(STR$(J));
NEXT J
PRINT
NEXT I
END
3 楼
冰冻小企鹅 [专家分:190] 发布于 2009-02-16 13:04:00
1楼的,虽然你做的太长,但是给你10分
[em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9]
4 楼
冰冻小企鹅 [专家分:190] 发布于 2009-02-16 13:06:00
二楼的,有创意!不错!
5 楼
冰冻小企鹅 [专家分:190] 发布于 2009-02-22 19:01:00
凡是回帖这都加分!!!!!!!!!!~~~~~~~~~~~~~~~~~~~~~~~~
[em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9][em9]
记得回复我哦!!!!!!!!!!!!!!!!!!!![em19][em19][em19][em19][em19][em19][em19][em19][em19][em19][em19][em19][em19][em19]
6 楼
hxy_anhui [专家分:320] 发布于 2009-03-28 20:34:00
我又更新了一种更简单的方法。
CLS
INPUT N
FOR I = -(N - 1) TO N - 1
PRINT TAB(ABS(I) + 1);
FOR J = -(N - ABS(I) - 1) TO N - ABS(I) - 1
PRINT LTRIM$(STR$(ABS(J)));
NEXT J
PRINT
NEXT I
END
我来回复