#include <stdio.h>
#include <stdlib.h>
// (Ⅱ)整数値を要素にもつk 行m 列行列A とm 行n 列行列B を宣言し,それらの要素をキーボー
// ドから入力してA×B を算出するプログラムを作成せよ.ただし,k,m,n はk≠m,m≠n,k≧2,
// m≧2,n≧2 を満たす任意の値をプログラム内で各自設定してよい.ただし,A×B の値を画面
// 表示する前に,k 行n列行列C に値を代入しておくこと.
char matName;
int mode;
// prototype
void input(int *a, int x, int y);
void calc(int *a1, int x1, int y1, int *a2, int x2, int y2, int *c);
void display(int *a, int x, int y);
void clear(int *a, int x, int y);
void calc(int *a1, int x1, int y1, int *a2, int x2, int y2, int *c)
{
int i, j;
for ( i = x1 * y1; i--;)
for ( j = x2 * y2; j--;)
if ((i % y1) == (j / y2))
*(c + (i / y1) *y2 + (j % y2)) += *(a1 + i) **(a2 + j);
}
void display(int *a, int x, int y)
{
int i;
for ( i = x * y; i--;) {
}
}
void input(int *a, int x, int y)
{
int i, j;
for ( i = 0; i < x; ++i)
for ( j = 0; j < y; ++j) {
if (mode) {
printf("%c[%d][%d]=", matName
, i
, j
); } else {
}
}
}
void clear(int *a, int x, int y)
{
int i;
for ( i = x * y; i--;) *a++ = 0;
}
int main()
{
int k = 3, m = 2, n = 4;
int A[k][m];
int B[m][n];
int C[k][n];
printf("0:debug 1:manual\n" );
matName = 'A';
input(*A, k, m);
matName = 'B';
input(*B, m, n);
clear(*C, k, n);
calc(*A, k, m, *B, m, n, *C);
display(*A, k, m);
display(*B, m, n);
display(*C, k, n);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KLy8gKOKFoSnmlbTmlbDlgKTjgpLopoHntKDjgavjgoLjgaRrIOihjG0g5YiX6KGM5YiXQSDjgahtIOihjG4g5YiX6KGM5YiXQiDjgpLlrqPoqIDjgZfvvIzjgZ3jgozjgonjga7opoHntKDjgpLjgq3jg7zjg5zjg7wKLy8g44OJ44GL44KJ5YWl5Yqb44GX44GmQcOXQiD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mErKyk7CiAgICBpZiAoaSAlIHkgPT0gMCkgcHV0Y2hhcignXG4nKTsKICB9CiAgcHV0Y2hhcignXG4nKTsKfQoKdm9pZCBpbnB1dChpbnQgKmEsIGludCB4LCBpbnQgeSkKewogIGludCBpLCBqOwoKICBmb3IgKCBpID0gMDsgaSA8IHg7ICsraSkKICAgIGZvciAoIGogPSAwOyBqIDwgeTsgKytqKSB7CiAgICAgIGlmIChtb2RlKSB7CiAgICAgICAgcHJpbnRmKCIlY1slZF1bJWRdPSIsIG1hdE5hbWUsIGksIGogKTsKICAgICAgICBzY2FuZigiJWQiLCBhKyspOwogICAgICB9IGVsc2UgewogICAgICAgICphKysgPSByYW5kKCkgJSAxMDsKICAgICAgfQogICAgfQp9Cgp2b2lkIGNsZWFyKGludCAqYSwgaW50IHgsIGludCB5KQp7CiAgaW50IGk7CiAgZm9yICggaSA9IHggKiB5OyBpLS07KSAqYSsrID0gMDsKfQoKCmludCBtYWluKCkKewogIGludCBrID0gMywgbSA9IDIsIG4gPSA0OwogIGludCBBW2tdW21dOwogIGludCBCW21dW25dOwogIGludCBDW2tdW25dOwoKICBwcmludGYoIjA6ZGVidWcgIDE6bWFudWFsXG4iICk7CiAgc2NhbmYoIiVkIiwgJm1vZGUpOwoKICBtYXROYW1lID0gJ0EnOwogIGlucHV0KCpBLCBrLCBtKTsKICBtYXROYW1lID0gJ0InOwogIGlucHV0KCpCLCBtLCBuKTsKCiAgY2xlYXIoKkMsIGssIG4pOwogIGNhbGMoKkEsIGssIG0sICpCLCBtLCBuLCAqQyk7CiAgZGlzcGxheSgqQSwgaywgbSk7CiAgZGlzcGxheSgqQiwgbSwgbik7CiAgZGlzcGxheSgqQywgaywgbik7CgogIHJldHVybiAwOwp9Cg==