Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. class fract
  7. {
  8. public:
  9. fract()
  10. {
  11. num = 0;
  12. denum = 1;
  13. }
  14. fract(int num, int denum)
  15. {
  16. this->num = num;
  17. this->denum = denum;
  18. }
  19. int num;
  20. int denum;
  21. };
  22.  
  23.  
  24. fract matrix[4][4];
  25.  
  26. void swap_rows(int n1, int n2)
  27. {
  28. for(int i = 0; i < 4; i++)
  29. {
  30. swap(matrix[n1][i], matrix[n2][i]);
  31. }
  32. }
  33.  
  34. void print_matr()
  35. {
  36. for(int i = 0; i < 4; i++)
  37. {
  38. for(int g = 0; g < 4; g++)
  39. cout << matrix[i][g].num << "/" << matrix[i][g].denum << " ";
  40. cout << endl;
  41. }
  42. }
  43.  
  44.  
  45. int main()
  46. {
  47. double max = 0;
  48. int num, imax;
  49. fract k;
  50. for(int i = 0; i < 4; i++)
  51. for(int g = 0; g < 4; g++)
  52. {
  53. cin >> num;
  54. matrix[i][g] = fract(num, 1);
  55. }
  56. for(int col = 0; col < 3; col++)
  57. {
  58. for(int row = col; row < 4; row++)
  59. {
  60. if(abs(double(matrix[row][col].num)/matrix[row][col].denum) >= max)
  61. {
  62. max = abs(double(matrix[row][col].num)/matrix[row][col].denum);
  63. imax = row;
  64. }
  65. }
  66. swap_rows(col, imax);
  67. print_matr();
  68. cout << endl << endl;
  69. for(int row = col + 1; row < 4; row++)
  70. {
  71. k = fract(-matrix[row][col].num * matrix[col][col].denum, matrix[row][col].denum * matrix[col][col].num);
  72. for(int column = col; column < 4; column++)
  73. {
  74. matrix[row][column] = fract(matrix[row][column].num*matrix[col][column].denum*k.denum + matrix[col][column].num*k.num*matrix[row][column].denum, matrix[row][column].denum*k.denum*matrix[col][column].denum);
  75. }
  76. }
  77. print_matr();
  78. cout << endl << endl;
  79. }
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement