Advertisement
STANAANDREY

sort_mat

Apr 17th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int a[100][100],n,m,i,j,k,aux;
  6. cout<<"n=";cin>>n;
  7. cout<<"m=";cin>>m;
  8. for (i=0;i<n;i++)
  9. for (j=0;j<m;j++)
  10. cin>>a[i][j];
  11. k=0;
  12. int temp[n*m];
  13. for (i=0;i<n;i++)
  14. for (j=0;j<m;j++) {
  15. temp[k]=a[i][j];
  16. k++;
  17. }
  18. for (i=0;i<k-1;i++)
  19. for (j=i+1;j<k;j++)
  20. if (temp[i]>temp[j])
  21. {
  22.     aux=temp[i];
  23.     temp[i]=temp[j];
  24.     temp[j]=aux;
  25. }
  26. k=0;
  27. for (i=0;i<n;i++)
  28. for (j=0;j<m;j++) {
  29. a[i][j]=temp[k];
  30. k++;
  31. }
  32. for(i=0;i<n;i++) {
  33.     for (j=0;j<m;j++)
  34.     cout<<a[i][j]<<' ';
  35.     cout<<endl;}//*/
  36.   return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement