fork download
  1. #include <stdio.h>
  2.  
  3. long cant=4,fila=0,colum=0,ctt=0;
  4. double a[4][5] =
  5. {
  6. {1, -2, 1, 1, 2},
  7. {3, 0, 2, -2, -8},
  8. {0, 4, -1, -1, 1},
  9. {5, 0, 3, -1, -3},
  10. };
  11. double res[10];
  12.  
  13. #define abs(x) ((x) > 0 ? (x) : (-x))
  14.  
  15. long jordan(){/*this do the gauss elimination for solve the equation*/
  16. long FilaMax=0,k=0;
  17. long double maxEl=0,tmp=0,fracc=0;
  18. for (colum=0; colum<cant-1; colum++) {
  19. /* search the maximun colum*/
  20. maxEl = abs(a[colum][colum]);
  21. FilaMax = colum;
  22. for (k=colum+1; k<cant; k++) {
  23. if (abs(a[k][colum]) > maxEl) {
  24. maxEl = abs(a[k][colum]);
  25. FilaMax = k;
  26. }
  27. }
  28. /* change the maximunby the actual row*/
  29. for (k=colum; k<cant+1;k++) {
  30. tmp = a[FilaMax][k];
  31. a[FilaMax][k] = a[colum][k];
  32. a[colum][k] = tmp;
  33. }
  34. /*lower cero's triangular matrix it's done here*/
  35. for (k=colum+1;k<cant; k++) {
  36. fracc = -a[k][colum]/a[colum][colum];
  37. for (fila=colum; fila<cant+1; fila++) {
  38. if (colum==fila) {
  39. a[k][fila] = 0;
  40. }else{
  41. a[k][fila] += fracc * a[colum][fila];
  42. }
  43. }
  44. }
  45. }
  46.  
  47. printf("%f\n", (float)a[cant-1][cant-1]);
  48. if(abs(a[cant-1][cant-1])<0.000001)
  49. printf("no solution found\n");
  50. else
  51. printf("solution found\n");
  52.  
  53. }
  54.  
  55. int main(void) {
  56. // your code goes here
  57. jordan();
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0s 2008KB
stdin
Standard input is empty
stdout
0.000000
no solution found