123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #include <stdio.h>
- void matrix_multiply(int A[][10], int B[][10], int C[][10], int A1, int A2, int B1, int B2) {
- int i,j,k;
- for (i = 0; i < A1; ++i) {
- for (j = 0; j < B2; ++j) {
- C[i][j] = 0;
- for (k = 0; k < A2; ++k) {
- C[i][j] += A[i][k] * B[k][j];
- }
- }
- }
- }
- int main() {
- int A1, A2, B1, B2,i,j;
- scanf("%d %d %d %d", &A1, &A2, &B1, &B2);
- int A[10][10], B[10][10], C[10][10];
- for (i = 0; i < A1; ++i) {
- for (j = 0; j < A2; ++j) {
- scanf("%d", &A[i][j]);
- }
- }
- for (i = 0; i < B1; ++i) {
- for (j = 0; j < B2; ++j) {
- scanf("%d", &B[i][j]);
- }
- }
- matrix_multiply(A, B, C, A1, A2, B1, B2);
- for (i = 0; i < A1; ++i) {
- for (j = 0; j < B2; ++j) {
- printf("%d", C[i][j]);
- if (j != B2 - 1) {
- printf(" ");
- }
- }
- printf("\n");
- }
- return 0;
- }
|