实现m*n矩阵与n*k矩阵的乘法用C语言实现
时间: 2023-12-31 11:06:24 浏览: 39
#include <stdio.h>
int main() {
int m, n, k;
printf("Enter the dimensions of the matrices: ");
scanf("%d %d %d", &m, &n, &k);
int A[m][n], B[n][k], C[m][k];
printf("Enter the elements of matrix A: \n");
for(int i=0; i<m; i++)
for(int j=0; j<n; j++)
scanf("%d", &A[i][j]);
printf("Enter the elements of matrix B: \n");
for(int i=0; i<n; i++)
for(int j=0; j<k; j++)
scanf("%d", &B[i][j]);
// Multiply matrices A and B
for(int i=0; i<m; i++) {
for(int j=0; j<k; j++) {
C[i][j] = 0;
for(int x=0; x<n; x++)
C[i][j] += A[i][x] * B[x][j];
}
}
// Print the resulting matrix C
printf("The result of matrix multiplication: \n");
for(int i=0; i<m; i++) {
for(int j=0; j<k; j++)
printf("%d ", C[i][j]);
printf("\n");
}
return 0;
}