Created
December 8, 2017 14:50
-
-
Save mi6112ogit/2a2c29a2ae3da762f1cb226f9a7a8e10 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> | |
//項の数 | |
#define N 2 | |
signed main(){ | |
double a[N][N+1]; | |
double d; | |
int i, j, k; | |
for(i = 0; i < N; i++){ | |
for(j = 0; j < N+1; j++){ | |
scanf("%lf", &a[i][j]); | |
} | |
} | |
//前進消去 | |
for(k = 0; k < N - 1; k++){ | |
for(i = k+1; i < N; i++){ | |
d = a[i][k] / a[k][k]; | |
for(j = k + 1; j <= N; j++){ | |
a[i][j] = a[i][j] - a[k][j] * d; | |
} | |
} | |
} | |
//後退代入 | |
for(i = N -1; i >= 0; i--){ | |
d = a[i][N]; | |
for(j = i + 1; j < N; j++){ | |
d = d - a[i][j] * a[j][N]; | |
} | |
a[i][N] = d / a[i][i]; | |
} | |
for(k = 0; k < N; k++){ | |
printf("%f\n", a[k][N]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment