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