fork download
  1. #include <stdio.h>
  2. #define N 2
  3.  
  4. void Gaussian_elimination(double a[N][N+1]){
  5. int i,j,k;
  6. double p,d;
  7.  
  8. for (i = 0; i < N; i++) {
  9. p = a[i][i];
  10. for (j = 0; j < (N + 1); j++) {
  11. a[i][j] = a[i][j] / p;
  12. }
  13. for (j = 0; j < N; j++) {
  14. if (i != j) {
  15. d = a[j][i];
  16. for (k = i; k < (N + 1); k++) {
  17. a[j][k] = a[j][k] - d * a[i][k];
  18. }
  19. }
  20. }
  21. }
  22. }
  23.  
  24. int main(void)
  25. {
  26. double a[N][N + 1] = {
  27. {0.08, 0.05, 21},
  28. {1.0, 1.0, 300}
  29. };
  30. char b[2][4]={"x", "y"};
  31. int i;
  32.  
  33. Gaussian_elimination(a);
  34.  
  35. for (i = 0; i < N; i++) {
  36. printf("%s = %f\n", b[i], a[i][N]);
  37. }
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
x = 200.000000
y = 100.000000