解题思路:
注意事项:
参考代码:
n = int(input())
l = [[0 for j in range(n)] for i in range(n)]
a = 1
b = 0
for i in range(n):
if b % 2 != 0:
for j in range(n):
if 0 <= i <=n-1 and 0 <= j <= n-1:
l[j][i] = a
a += 1
i -= 1
else:
break
b += 1
else:
for j in range(n):
if 0 <= i <=n-1 and 0 <= j <= n-1:
l[i][j] = a
a += 1
i -= 1
else:
break
b += 1
a = n*n
b = 0
for i in range(n-1,0,-1):
if b % 2 != 0:
for j in range(n-1,0,-1):
if 0 <= i <=n-1 and 0 <= j <= n-1:
l[j][i] = a
a -= 1
i += 1
else:
break
b += 1
else:
for j in range(n-1,0,-1):
if 0 <= i <=n-1 and 0 <= j <= n-1:
l[i][j] = a
a -= 1
i += 1
else:
break
b += 1
for i in l:
print(* i)
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:699 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:631 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)浏览:2098 |
复数求和 (C语言代码)浏览:994 |
数组输出 (C语言代码)浏览:749 |
淘淘的名单 (C语言代码)浏览:1309 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:494 |
C语言程序设计教程(第三版)课后习题9.2 (C语言代码)浏览:646 |
简单的a+b (C语言代码)浏览:617 |
老王赛马 (C++代码)浏览:973 |