矩阵相乘的问题
#include<stdio.h>void matrix_multiply(int x, int y, int z, int m1[][y], int m2[][z], int r[][z]);
int main(void)
{
int x = 2;
int y = 3;
int z = 4;
int m1[x][y] = {{2,-6},
{3,5},
{ 1,-1},
};
int m2[y][z] = {{4,-2,-4,-5},
{-7,-3,5,7},
};
int r[x][z];
matrix_multiply(m1,m2,r,x,y,z);
return 0;
}
void matrix_multiply(int x,int y, int z,int m1[][y], int m2[][z], int r[][z])
{
int i,j,k;
int sum ;
for(k = 0; k < z; k++)
{
for(j = 0; j < y; j++)
{
sum = 0;
for(i = 0; i < 2; i++)
{
sum = sum + m1[x][i] * m2[i][y];
}
r[i][k] = sum;
printf("%5d", r[i][k]);
}
printf("\n");
}
}
定义函数的时候总是有错误,希望大神指点
[此贴子已经被作者于2017-1-24 15:10编辑过]