fork(1) 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. {1.0, 1.0, 8},
  28. {230, 310, 2080}
  29. };
  30. char *b[3]={"リンゴ","モモ"};
  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. }
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
リンゴ = 5.000000
モモ = 3.000000