1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <iostream>
using namespace std;
const int SIZEQ4 = 4;
const int ROWS = 4;
void changingTheNumbersOrderFromTheSmallestToTheBiggestQ4(int matrixQ4[][SIZEQ4],int rows, int size);
void main()
{
int matrixQ4[SIZEQ4][SIZEQ4] = { { 3,4,1,2 },{ 7, 5, 6, 9 },{ 8, 10, 13, 12, },{ 11, 14, 15, 16 } };
int i, j;
changingTheNumbersOrderFromTheSmallestToTheBiggestQ4(matrixQ4, ROWS, SIZEQ4);
for (int i = 0; i < SIZEQ4; i++)
{
for (j = 0; j < SIZEQ4; j++)
{
cout << matrixQ4[i][j] << " ";
}
cout << endl;
}
system("pause");
}
void changingTheNumbersOrderFromTheSmallestToTheBiggestQ4(int matrixQ4[][SIZEQ4], int rows, int size)
{
int i, j,k;
int temp;
for (i = 0; i < size*rows -1 ; i++)
{
for (k = 0; k < size - 1; k++)
{
for (j = 0; j <size -1; j++)
{
if (matrixQ4[k][j] > matrixQ4[k][j + 1])
{
temp = matrixQ4[k][j];
matrixQ4[k][j] = matrixQ4[k][j + 1];
matrixQ4[k][j + 1] = temp;
}
}
}
}
}
|