#include <stdio.h>
#define N 2
void Gaussian_elimination(double a[N][N+1]){
int i,j,k;
double p,d;
for (i = 0; i < N; i++) {
p = a[i][i];
for (j = 0; j < (N + 1); j++) {
a[i][j] = a[i][j] / p;
}
for (j = 0; j < N; j++) {
if (i != j) {
d = a[j][i];
for (k = i; k < (N + 1); k++) {
a[j][k] = a[j][k] - d * a[i][k];
}
}
}
}
}
int main(void)
{
// 連立方程式を表す係数行列
// x + y = 300
// 0.08x + 0.05y = 21
double a[N][N + 1] = {
{1.0, 1.0, 300},
{0.08, 0.05, 21}
};
char b[2][4] = {"x", "y"};
int i;
// ガウスの消去法を使って連立方程式を解く
Gaussian_elimination(a);
// 結果を表示
for (i = 0; i < N; i++) {
printf("%s = %f\n", b
[i
], a
[i
][N
]); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNkZWZpbmUgTiAyCgp2b2lkIEdhdXNzaWFuX2VsaW1pbmF0aW9uKGRvdWJsZSBhW05dW04rMV0pewogICAgaW50IGksaixrOwogICAgZG91YmxlIHAsZDsKICAgIAogICAgZm9yIChpID0gMDsgaSA8IE47IGkrKykgewogICAgICAgIHAgPSBhW2ldW2ldOwogICAgICAgIGZvciAoaiA9IDA7IGogPCAoTiArIDEpOyBqKyspIHsKICAgICAgICAgICAgYVtpXVtqXSA9IGFbaV1bal0gLyBwOwogICAgICAgIH0KICAgICAgICBmb3IgKGogPSAwOyBqIDwgTjsgaisrKSB7CiAgICAgICAgICAgIGlmIChpICE9IGopIHsKICAgICAgICAgICAgICAgIGQgPSBhW2pdW2ldOwogICAgICAgICAgICAgICAgZm9yIChrID0gaTsgayA8IChOICsgMSk7IGsrKykgewogICAgICAgICAgICAgICAgICAgIGFbal1ba10gPSBhW2pdW2tdIC0gZCAqIGFbaV1ba107CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgfQp9CiAKaW50IG1haW4odm9pZCkKewogICAgLy8g6YCj56uL5pa556iL5byP44KS6KGo44GZ5L+C5pWw6KGM5YiXCiAgICAvLyB4ICsgeSA9IDMwMAogICAgLy8gMC4wOHggKyAwLjA1eSA9IDIxCiAgICBkb3VibGUgYVtOXVtOICsgMV0gPSB7CiAgICAgICAgezEuMCwgMS4wLCAzMDB9LAogICAgICAgIHswLjA4LCAwLjA1LCAyMX0KICAgIH07CiAgICBjaGFyIGJbMl1bNF0gPSB7IngiLCAieSJ9OwogICAgaW50IGk7CiAgCiAgICAvLyDjgqzjgqbjgrnjga7mtojljrvms5XjgpLkvb/jgaPjgabpgKPnq4vmlrnnqIvlvI/jgpLop6PjgY8KICAgIEdhdXNzaWFuX2VsaW1pbmF0aW9uKGEpOyAKIAogICAgLy8g57WQ5p6c44KS6KGo56S6CiAgICBmb3IgKGkgPSAwOyBpIDwgTjsgaSsrKSB7CiAgICAgICAgcHJpbnRmKCIlcyA9ICVmXG4iLCBiW2ldLCBhW2ldW05dKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=