Răspuns :
#include <iostream>
using namespace std;
//Alocare dinamica matrice
int** alocare_matrice(int nLinii, int nColoane) {
int** p = new int* [nLinii];
for (int index = 0; index < nLinii; index++)
p[index] = new int[nColoane];
return p;
}
//Citire date
int** citire_date(int& nLinii, int& nColoane) {
cout << "Numarul de linii : ", cin >> nLinii;
cout << "Numarul de coloane : ", cin >> nColoane;
int** matrice = alocare_matrice(nLinii, nColoane);
cout << "Introduceti elementele matricei :\n";
for (int linie = 0; linie < nLinii; linie++) {
for (int coloana = 0; coloana < nLinii; coloana++) {
cin >> matrice[linie][coloana];
}
}
return matrice;
}
//Dealocare matrice
void dealocare_matrice(int** matrice, int nLinii) {
for (int index = 0; index < nLinii; index++)
delete[] matrice[index];
delete[] matrice;
}
int main() {
int n, m, ** mat;
mat = citire_date(n, m);
cout << "\nLinii sortate :";
//Verificare linii
int i, j;
for (i = 0; i < n; i++) {
//Verificare daca linia e sortata
bool sortat = 1;
for (j = 0; j < m - 1; j++)
if (mat[i][j] > mat[i][j + 1]) sortat = 0;
//Afisare daca linia e sortata
if (sortat) {
cout << endl;
for (j = 0; j < m; j++)
cout << mat[i][j] << " ";
}
}
cout << "\nColoane sortate :";
//Verificare coloane
for (j = 0; j < m; j++) {
//Verificare daca coloana e sortata
bool sortat = 1;
for (i = 0; i < n - 1; i++)
if (mat[i][j] > mat[i+1][j]) sortat = 0;
//Afisare daca linia e sortata
if (sortat) {
cout << endl;
for (i = 0; i < n; i++)
cout << mat[i][j] << " ";
}
}
}