Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- class fract
- {
- public:
- fract()
- {
- num = 0;
- denum = 1;
- }
- fract(int num, int denum)
- {
- this->num = num;
- this->denum = denum;
- }
- int num;
- int denum;
- };
- fract matrix[4][4];
- void swap_rows(int n1, int n2)
- {
- for(int i = 0; i < 4; i++)
- {
- swap(matrix[n1][i], matrix[n2][i]);
- }
- }
- void print_matr()
- {
- for(int i = 0; i < 4; i++)
- {
- for(int g = 0; g < 4; g++)
- cout << matrix[i][g].num << "/" << matrix[i][g].denum << " ";
- cout << endl;
- }
- }
- int main()
- {
- double max = 0;
- int num, imax;
- fract k;
- for(int i = 0; i < 4; i++)
- for(int g = 0; g < 4; g++)
- {
- cin >> num;
- matrix[i][g] = fract(num, 1);
- }
- for(int col = 0; col < 3; col++)
- {
- for(int row = col; row < 4; row++)
- {
- if(abs(double(matrix[row][col].num)/matrix[row][col].denum) >= max)
- {
- max = abs(double(matrix[row][col].num)/matrix[row][col].denum);
- imax = row;
- }
- }
- swap_rows(col, imax);
- print_matr();
- cout << endl << endl;
- for(int row = col + 1; row < 4; row++)
- {
- k = fract(-matrix[row][col].num * matrix[col][col].denum, matrix[row][col].denum * matrix[col][col].num);
- for(int column = col; column < 4; column++)
- {
- 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);
- }
- }
- print_matr();
- cout << endl << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement