Advertisement
iamthehxc

Untitled

Jul 22nd, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. void sortarray(int array[][],int row,int col);
  3. int main ()
  4. {
  5. int array[3][5]={{4,1,3,0},{2,9,7,5},{6,5,8,1}};
  6. int row=3;
  7. int col=4;
  8. int i,j;
  9.  
  10. printf("The 2D array is: \n");
  11. for(i=0; i<row; i++)
  12. {
  13. for(j=0; j<col; j++)
  14. printf("%2d ", array[i][j]);
  15. printf("\n");
  16. }
  17.  
  18. sortarray(array,row,col);
  19.  
  20. system("PAUSE");
  21. return 0;
  22. }
  23.  
  24. void sortarray(int array[][],int row,int col)
  25. {
  26. int temp, i, j;
  27. printf("\nThe sorted 2D array is: \n");
  28.  
  29. for(i=0; i<row; i++)
  30. {
  31. for(j=1; j<col; j++)
  32. {
  33. if(array[i][j]<array[i][j+1])
  34. {
  35. temp=array[i][j-1];
  36. array[i][j-1]=array[i][j];
  37. array[i][j]=temp;
  38. }
  39. }
  40. }
  41. for(i=0; i<row; i++)
  42. {
  43. for(j=0; j<col; j++)
  44. printf("%2d ", array[i][j]);
  45. printf("\n");
  46. }
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement