Row wise sorting in 2D array | C ++ code to sort 2D matrix row - wise ; One by one sort individual rows . ; Printing the sorted matrix ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define M  4 NEW_LINE #define N  4 NEW_LINE int sortRowWise ( int m [ M ] [ N ] ) { for ( int i = 0 ; i < M ; i ++ ) sort ( m [ i ] , m [ i ] + N ) ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) cout << ( m [ i ] [ j ] ) << " ▁ " ; cout << endl ; } } int main ( ) { int m [ M ] [ N ] = { { 9 , 8 , 7 , 1 } , { 7 , 3 , 0 , 2 } , { 9 , 5 , 3 , 2 } , { 6 , 3 , 1 , 2 } } ; sortRowWise ( m ) ; }