说到矩阵乘法,最先想到的就是用两个for循环,循环矩阵A的行再循环矩阵B的列,从而实现矩阵A与B的相乘。
(1)下面是串行算法的实现代码:
#include
#include
typedef struct
{
int** mat;//指向指针的指针
int row,col;
}matrix;
void initial(matrix &M,int row,int col)
{
int i,j = 0;
M.mat = (int **)malloc(row*sizeof(int *));//分配列空间
for (i = 0; i < row; i++)
M.mat[i] = (int *)malloc(col*sizeof(int));//分配行空间
M.row = row;
M.col = col;
}
void initValue(matrix &M, int row, int col)
{
int i, j;
initial(M,row,col);
for (i = 0; i < row; i++)
{
printf("请输入第%d行的数据:",i);
for (j = 0; j < col; j++)
scanf("%d",&M.mat[i][j]);
}
}
void Matri