Skip to content

Instantly share code, notes, and snippets.

@mi6112ogit
Created December 8, 2017 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mi6112ogit/2a2c29a2ae3da762f1cb226f9a7a8e10 to your computer and use it in GitHub Desktop.
Save mi6112ogit/2a2c29a2ae3da762f1cb226f9a7a8e10 to your computer and use it in GitHub Desktop.
#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