程序代码:
#include<stdio.h>
#include<iostream>
#define m 3
int main()
{
int i, j, k;
int a[m][m], b[m][m], c[m][m];
/*为需要相乘的两个矩阵赋值:*/
printf("输入第一个矩阵:\n");
for (i = 0; i < m; i++)
for (j = 0; j < m; j++)
scanf("%d", &a[i][j]);
printf("输入第二个矩阵:\n");
for (i = 0; i < m; i++)
for (j = 0; j < m; j++)
scanf("%d", &b[i][j]);
/*初始化m:*/
for (i = 0; i < m; i++)
for (j = 0; j < m; j++)
c[i][j] = 0;
for (i = 0; i<m; i++)
for (j = 0; j < m; j++)
{
c[i][j] = 0;
for (k = 0; k < m; k++)
c[i][j] += a[i][k] * b[k][j];
}
for (i = 0; i < m; i++)
for (j = 0; j < m; j++)
printf("%5d", c[i][j]);
printf("\n");
return 0;
}