Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iomanip>
- #include <iostream>
- using namespace std;
- int main() {
- double** matrix;
- int m, n;
- cout << "Enter m: ";
- cin >> m;
- if (m <= 0) {
- cout << "M must be positive";
- return 0;
- }
- cout << "Enter n: ";
- cin >> n;
- if (n <= 0) {
- cout << "N must be positive";
- return 0;
- }
- matrix = new double*[m];
- for (int i = 0; i < m; i++) {
- matrix[i] = new double[n];
- }
- int maxI = 0, maxJ = 0;
- cout << "Fill matrix:" << endl;
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- cout << "[" << i << "][" << j << "]) ";
- cin >> matrix[i][j];
- if (matrix[maxI][maxJ] < matrix[i][j]) {
- maxI = i;
- maxJ = j;
- }
- }
- }
- cout << endl << "Your array:" << endl;
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- cout << setw(4) << matrix[i][j] << " ";
- }
- cout << endl;
- }
- // swaping row
- double* temp = matrix[0];
- matrix[0] = matrix[maxI];
- matrix[maxI] = temp;
- // u can remove
- cout << endl << "Your array after swapping row:" << endl;
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- cout << setw(4) << matrix[i][j] << " ";
- }
- cout << endl;
- }
- // swaping column
- for (int i = 0; i < m; i++) {
- double temp = matrix[i][0];
- matrix[i][0] = matrix[i][maxJ];
- matrix[i][maxJ] = temp;
- }
- cout << endl << "Your array after swapping column:" << endl;
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- cout << setw(4) << matrix[i][j] << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement