帮我写:输入一个2乘3数组,交换行和列,输出对应的3乘2数组
时间: 2024-03-17 21:42:31 浏览: 43
java代码-使用java定义一个2行3列的整型数组的源代码
好的,以下是示例代码:
```python
# 定义一个2乘3二维数组
arr = [[0 for j in range(3)] for i in range(2)]
# 输入数组
print("请输入2*3数组:")
for i in range(2):
for j in range(3):
arr[i][j] = int(input())
# 输出原数组
print("原数组:")
for i in range(2):
for j in range(3):
print(arr[i][j], end=" ")
print()
# 交换行和列
for i in range(3):
for j in range(i, 2):
temp = arr[j][i]
arr[j][i] = arr[i][j]
arr[i][j] = temp
# 输出结果数组
print("结果数组:")
for i in range(3):
for j in range(2):
print(arr[i][j], end=" ")
print()
```
输入示例:
```
1 2 3
4 5 6
```
输出示例:
```
原数组:
1 2 3
4 5 6
结果数组:
1 4
2 5
3 6
```
阅读全文