实现m*n矩阵与n*k矩阵的乘法用C语言实现
时间: 2023-12-31 20:06:24 浏览: 37
#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;
}
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)