我已经在另一个问题里面回答了这一题
链接为
http://zhidao.baidu.com/question/1110362592432240339.html下面为详细代码
#include <stdio.h>
#include <stdlib.h>
int **cal(int a[][3], int b[][3]);
int main() {
int a[3][3], b[3][3], i, j;
for (i = 0; i < 3; i++)//输入数组a
for (j = 0; j < 3; j++)
scanf("%d", &a[i][j]);
for (i = 0; i < 3; i++)//输入数组b
for (j = 0; j < 3; j++)
scanf("%d", &b[i][j]);
int **mul = cal(a, b);//计算矩阵乘积
for (i = 0; i < 3; i++)//打印
printf("%d %d %d\n", mul[i][0], mul[i][1], mul[i][2]);
for (i = 0; i < 3; i++)//释放动态数组
free(mul[i]);
free(mul);
return 0;
}
int **cal(int a[][3], int b[][3]) {
//创建动态数组
int **p = (int **) malloc(3 * sizeof(int *)), i, j;
for (i = 0; i < 3; i++)
p[i] = (int *) malloc(3 * sizeof(int));
//计算
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
p[i][j] = a[i][0] * b[0][j] + a[i][1] * b[1][j] + a[i][2] * b[2][j];
return p;
}