Last active
December 13, 2018 15:43
-
-
Save kana-ph/430d4d1e43d522d664784ddd7c4652df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void print_matrix(int m, int n, int matrix[m][n]); | |
void multiply(int n, int m, int p, int a[n][m], int b[m][p], int c[n][p]); | |
int main() { | |
int x[3][2] = { | |
{1, 2}, | |
{3, 4}, | |
{5, 6} | |
}; | |
int y[2][4] = { | |
{ 7, 8, 9, 10}, | |
{11, 12, 13, 14} | |
}; | |
int m[3][4] = { | |
{0, 0, 0, 0}, | |
{0, 0, 0, 0}, | |
{0, 0, 0, 0} | |
}; | |
print_matrix(3, 2, x); | |
printf("---------\n"); | |
print_matrix(2, 4, y); | |
printf("---------\n"); | |
multiply(3, 2, 4, x, y, m); | |
print_matrix(3, 4, m); | |
printf("\n"); | |
return 0; | |
} | |
void print_matrix(int m, int n, int matrix[m][n]) { | |
int i; | |
int j; | |
for (i = 0; i < m; i++) { | |
for (j = 0; j < n; j++) { | |
printf("%5d", matrix[i][j]); | |
} | |
printf("\n"); | |
} | |
} | |
void multiply(int n, int m, int p, int a[n][m], int b[m][p], int c[n][p]) { | |
int i; | |
int j; | |
int k; | |
int sum; | |
for (i = 0; i < n; i++) { | |
for (j = 0; j < p; j++) { | |
sum = 0; | |
for (k = 0; k < m; k++) { | |
sum += a[i][k] * b[k][j]; | |
} | |
c[i][j] = sum; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment