Skip to content

Instantly share code, notes, and snippets.

@andrinur13
Created May 17, 2019 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrinur13/98dcdb6bddac0119040824f018fcf222 to your computer and use it in GitHub Desktop.
Save andrinur13/98dcdb6bddac0119040824f018fcf222 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
main() {
int angka[3][4] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{2, 3, 5, 4}
};
// for(int i=0; i<3; i++) {
// for(int j=0; j<4; j++) {
// cout << angka[j] << " ";
// }
// cout << endl;
// }
cout << endl;
// for(int i=0; i<3; i++) {
// for(int j=0; j<4; j++) {
// if(angka[j]%2 != 0) {
// for(int k=j+1; k<4; k++) {
// if(angka[k]%2 == 0) {
// temp = angka[j];
// angka[j] = angka[k];
// angka[k] = temp;
// }
// }
// }
// }
// }
for(int i=0; i<3; i++) {
for(int j=0; j<4; j++) {
cout << angka[i][j] << " ";
}
cout << endl;
}
cout << "oke" << endl;
int temp;
for(int i=0; i<3; i++) {
for(int j=0; j<4; j++) {
if(angka[i][j] % 2 != 0) {
for(int k=1; k<4; k++) {
if(angka[j][k] % 2 == 0) {
temp = angka[i][j];
angka[i][j] = angka[i][k];
angka[i][k] = temp;
}
}
}
}
}
for(int i=0; i<3; i++) {
for(int j=0; j<4; j++) {
cout << angka[i][j] << " ";
}
cout << endl;
}
// for(int i=0; i<3; i++) {
// for(int j=0; j<4; j++) {
// cout << angka[j] << " ";
// }
// cout << endl;
// }
cout << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment