Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void sortarray(int array[3][4],int row,int col);
- int main (){
- int array[3][4]={{4,1,3,0},{2,9,7,5},{6,5,8,1}};
- int row=3;
- int col=4;
- int i,j;
- printf("The 2D array is: \n");
- for(i=0; i<row; i++){
- for(j=0; j<col; j++)
- printf("%2d ", array[i][j]);
- printf("\n");
- }
- printf("\nThe sorted 2D array is: \n");
- sortarray(array,row,col);
- system("PAUSE");
- return 0;
- }
- void sortarray(int array[3][4],int row,int col){
- int i,j,k,temp=0;
- for(k=0;k<row;k++){
- for(i=0;i<col;i++){
- for(j=i;j<=col+1;j++){
- if(array[k][j]<array[k][i]){
- temp=array[k][i];
- array[k][i]=array[k][j];
- array[k][j]=temp;
- }
- }
- }
- }
- for(k=0;k<row;k++){
- for(j=0; j<col;j++)
- printf("%2d ", array[k][j]);
- printf("\n");
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement