1.矩阵乘积
#include<stdio.h>
#include<string.h>
#define N 2
#define M 3
#define P 2
int main()
{
int i, j, k, a[N][M], b[M][P], c[N][P], s;
printf("input matrix A[2][3]\n");
for (i = 0; i < N; i++)
for (j = 0; j < M; j++)
scanf("%d", &a[i][j]);
printf("input matrix B[3][2]\n");
for (i = 0; i < M; i++)
for (j = 0; j < P; j++)
scanf("%d", &b[i][j]);
for (i = 0; i < N; i++)
{
for (j = 0; j < P; j++)
{
for (k = 0, s = 0; k < M; k++)
s += a[i][k] * b[k][j];
c[i][j] = s;
}
}
printf(" matrix C[2][2]\n");
for (i = 0; i < N; i++)
{
for (j = 0; j < P; j++)
printf("%6d", c[i][j]);
printf("\n");
}
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/2024ce0b7353cafc17f8d336f1e84bdc.png)
2.矩阵转置
#include<stdio.h>
#include<string.h>
#define N 2
#define M 3
#define P 2
int main()
{
int i, j, a[N][M], b[M][P];
for (i = 0; i < N; i++)
{
for (j = 0; j < M; j++)
scanf("%d", &a[i][j]);
}
for (i = 0; i < M; i++)
{
for (j = 0; j < N; j++)
b[i][j] = a[j][i];
}
for (i = 0; i < M; i++)
{
for (j = 0; j < N; j++)
printf("%d ", b[i][j]);
printf("\n");
}
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/60a323ee45ab41a36b49a4a8364d2445.png)