Advertisement
icatalin

sortrare materice metoda 3

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