蓝桥杯-算法训练-矩阵运算
时间: 2024-01-08 10:03:39 浏览: 144
以下是一个关于矩阵运算的示例程序:
```python
n = int(input()) # 矩阵的大小
= [] # 原矩阵
b = [] # 转置后的矩阵
c = [] # 相加后的矩阵
# 输入原矩阵
for i in range(n):
temp = list(map(int, input().split()))
a.append(temp)
# 转置矩阵
for i in range(n):
t = []
for j in range(n):
t.append(a[j][i])
b.append(t)
# 相加矩阵
for i in range(n):
t = []
for j in range(n):
t.append(0)
c.append(t)
for i in range(n):
for j in range(n):
c[i][j] = a[i][j] + b[i][j]
# 输出相加后的矩阵
for i in range(n):
for j in range(n):
print(c[i][j], end=' ')
print()
```
阅读全文