// matmult1.c #include #include /* a11 a12 a13 b11 b12 a11*b11+a12*b21+a13*b31 a11*b12+a12*b22+a13*b32 a21 a22 a23 x b21 b22 = a21*b11+a22*b21+a23*b31 a21*b12+a22*b22+a23*b32 b31 b32 */ void mat_in(int a[ ][10], int * m, int * n, char * in_file); void mat_out(int a[ ][10], int m, int n); void mat_mult(int a[ ][10], int b[ ][10], int c[ ][10], int m, int n, int o); int main(void) { int mat1[10][10], mat2[10][10], mat3[10][10]; int m,n,o; mat_in(mat1, &m, &n, "c:/MyFiles/CourseW2015/mat1.data"); mat_out(mat1, m, n); mat_in(mat2, &n, &o, "c:/MyFiles/CourseW2015/mat2.data"); mat_out(mat2, n, o); mat_mult(mat1, mat2, mat3, m, n, o); mat_out(mat3, m, o); return 0; } void mat_in(int a[ ][10], int * rows, int * cols, char * in_file) { int i, j; FILE * in; in = fopen(in_file,"r"); fscanf(in, "%d %d", rows, cols); for(i=0; i<*rows; i++) for(j=0; j<*cols; j++) fscanf(in,"%d", &a[i][j]); } void mat_out(int a[ ][10], int m, int n) { int i, j; printf("%d %d \n\n", m, n); for(i=0; i #include void mat_in(int a[ ][10], int * m, int * n, char in_file[ ]); void mat_out(int a[ ][10], int m, int n); void mat_mult(int a[ ][10], int b[ ][10], int c[ ][10], int m, int n, int o); int main(void) { int mat1[10][10], mat2[10][10], mat3[10][10]; int m,n,o; char name[40]; strcpy(name, "c:/MyFiles/CourseW2015/mat1.data"); mat_in(mat1, &m, &n, name); mat_out(mat1, m, n); strcpy(name, "c:/MyFiles/CourseW2015/mat2.data"); mat_in(mat2, &n, &o, name); mat_out(mat2, n, o); mat_mult(mat1, mat2, mat3, m, n, o); mat_out(mat3, m, o); return 0; } void mat_in(int a[ ][10], int * rows, int * cols, char in_file[ ]) { int i, j; FILE * in; in = fopen(in_file,"r"); fscanf(in, "%d %d", rows, cols); for(i=0; i<*rows; i++) for(j=0; j<*cols; j++) fscanf(in,"%d", &a[i][j]); } void mat_out(int a[ ][10], int m, int n) { int i, j; printf("%d %d \n\n", m, n); for(i=0; i