主题:QB新入门的学员请教高手两道数组题
羽馨1972
[专家分:0] 发布于 2011-10-13 15:36:00
1, 从键盘输入n(0<n<10),输出对应的数字图形。例如N=5时,输出图形如下:
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
2, 从键盘输入n (0<n<10) ,输入对应的数字方阵。例如 N=6时, 输出方阵如下:
1 1 1 1 1 1
1 2 1 1 2 1
1 1 3 3 1 1
1 1 4 4 1 1
1 5 1 1 5 1
6 1 1 1 1 6
回复列表 (共4个回复)
沙发
羽馨1972 [专家分:0] 发布于 2011-10-13 19:27:00
请教高手,多谢!!!盼回复!!!
板凳
羽馨1972 [专家分:0] 发布于 2011-10-14 12:33:00
答案出来了,请高手指教
1. OPTION BASE 1
DO
INPUT "N="; N
LOOP UNTIL N > 0 AND N <= 10
DIM A(N, N)
FOR I = 1 TO N
FOR J = 1 TO N
A(I, J) = I + J - 1
IF A(I, J) > N THEN A(I, J) = A(I, J) - N
NEXT J
NEXT I
FOR I = 1 TO N
FOR J = 1 TO N
PRINT A(I, J);
NEXT J
PRINT
NEXT I
END
3 楼
羽馨1972 [专家分:0] 发布于 2011-10-14 12:34:00
2.
cls
do
input "n=";n
loop until n > 0 and n < 10
for i = 1 to n
for j = 1 to n
a( i , j ) = 1
next j , i
for i = 1 to n
a( i , i ) = i
a( i , n + 1 - i ) = i
next i
for i = 1 to n
for j = 1 to n
print a( i , j );
next j
print
next i
end
4 楼
幽灵密码 [专家分:3510] 发布于 2011-10-14 18:07:00
OPTION BASE 1?用这个干吗
我来回复