1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include using namespace std; int main() { int n,m,i,j,matrik[1000][101],aux,ok; cin>>n>>m; for(i=1;i<=n;i++) for(j=1;j<=m;j++) cin>>matrik[i][j]; do{ok=1; for(j=1;j<m;j++) if(matrik[1][j]>matrik[1][j+1]) { for(i=1;i<=n;i++){ aux=matrik[i][j+1]; matrik[i][j+1]=matrik[i][j]; matrik[i][j]=aux;} ok=0; } }while(!ok); for(i=1;i<=n;i++){ for(j=1;j<=m;j++) cout<<matrik[i][j]<<" "; cout<<endl; } }