Advertisement
Guest User

Untitled

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