Не помню точно, эта или или нет, давно писал, надеюсь поможет.
//2. Сортування матриці
void FillMat(int arr[][5], int row, int col)
{
for(int i=0; i<row; i++)
{
for(int j=0; j<col; j++)
{
arr[i][j]=rand()%50;
}
}
}
void PrintMat(int arr[][5], int row, int col)
{
for(int i=0; i<row; i++)
{
for(int j=0; j<col; j++)
{
cout<<arr[i][j]<<"\t";
}
cout<<endl;
}
}
void SortMat(int arr[][5], int row, int col)
{
for (int i=0;i<row;i++)
{
for (int j=0;j<col-1;j++)
{
bool flag=false;
for (int q=col-1;q>j;q--)
{
if (arr[i][q]<arr[i][q-1])
{
int tmp=arr[i][q];
arr[i][q]=arr[i][q-1];
arr[i][q-1]=tmp;
flag=true;
}
}
if (flag=false)
{
break;
}
}
}
}
void main ()
{
srand (time(0));
int const row=5;
int const col=5;
int arr[row][col];
FillMat(arr, row, col);
PrintMat(arr, row, col);
cout<<endl;
SortMat(arr, row, col);
PrintMat(arr, row, col);
cout<<endl;
}