Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void Xuat(int A[][4], int row, int col);
- void Sort(int A[][4], int row, int col);
- void swap(int A[][4], int iR, int iC, int jR, int jC);
- int main()
- {
- int A[4][4]=
- {
- {7,4,0,4},
- {3,8,1,5},
- {9,2,6,3},
- {1,0,3,7}
- };
- int row=4;
- int col=4;
- //Xuat(A,row,col);
- Sort(A,row,col);
- Xuat(A,row,col);
- return 0;
- }
- void Xuat(int A[][4], int row, int col)
- {
- for (int i=0;i<row;i++)
- {
- for (int j=0;j<col;j++)
- printf("%d ",A[i][j]);
- printf("\n");
- }
- }
- void Sort(int A[][4], int row, int col)
- {
- for (int i=0;i<row*col-1;i++)
- for (int j=i+1;j<row*col;j++)
- {
- if (A[i/col][i%col]>A[j/col][j%col])
- swap(A,i/col,i%col,j/col,j%col);
- }
- for (int i=1;i<row;i+=2)
- for (int j=0;j<col/2;j++)
- swap(A,i,j,i,col-j-1);
- }
- void swap(int A[][4], int iR, int iC, int jR, int jC)
- {
- int tmp=A[iR][iC];
- A[iR][iC]=A[jR][jC];
- A[jR][jC]=tmp;
- }
- /*
- 00 01 02 03 04 05 06 07 08 09
- 10 11 12 13 14 15 16 17 18 19
- 20 21 22 23 24 25 26 27 28 29
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement