Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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
You can’t perform that action at this time.