Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int count = 5;
- int i, j, pass = 0;
- double temp;
- bool done = false;
- int lastIndex = 0;
- int arr[5] = {2,3,4,5,6};
- while (!done) {
- lastIndex = 0;
- for (int i = 0; i < count - 1; i++) {
- if (arr[i] % 2 != 0 && arr[i + 1] % 2 == 0) {
- temp = arr[i + 1];
- arr[i + 1] = arr[i];
- arr[i] = temp;
- break;
- } else {
- lastIndex++;
- }
- if (lastIndex == count - 1) {
- done = true;
- }
- }
- }
- for (int x = 0; x < count; x++) {
- cout << arr[x] << ", ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement