fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iomanip>
  4. using namespace std;
  5. const int M = 10;
  6. void fun(double a[][M])
  7. { for (int i = 0; i < M / 2; ++i)
  8. { for (int j = 0; j < M; j++)
  9. { swap(a[i][j], a[M - i - 1][j]);
  10. }
  11. }
  12. }
  13.  
  14. void gauss(double a[][M], int r, int c) {
  15. for (int i; i < min(r, c) - 1; i++) {
  16. for (int j = i + 1; j < r; j++) {
  17. if (a[i][i] == 0) fun(a);
  18. for (int l = 0; l < c; l++) {
  19. a[j][l] -= a[i][l] / a[i][i]* a[j][i] ;
  20. }
  21. }
  22. }
  23. }
  24. int main()
  25. {
  26. double a[M][M];
  27. int r, c;
  28. cin >> r;//строки
  29. cin >> c;//столбцы
  30.  
  31. for (int i = 0; i < r; i++)
  32. {
  33. for (int j = 0; j < c; j++)
  34. {
  35. cin >> a[i][j];
  36. }
  37. }
  38. gauss(a, r, c);
  39.  
  40. cout << "Матрица Гаусcа" << endl;
  41. for (int i = 0; i < r; i++)
  42. {
  43. for (int j = 0; j < c; j++)
  44. cout << setw(10) << a[i][j];
  45. cout << endl;
  46. }
  47. return 0;
  48. }
  49.  
  50.  
Success #stdin #stdout 0s 4336KB
stdin
3
3
10
2
5
-7
4
3
6
7
3
stdout
Матрица Гаусcа
        10         2         5
         0         4         3
         0         0         3