SHARE
TWEET

Untitled

a guest Dec 8th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7.     int count = 5;
  8.  
  9.     int i, j, pass = 0;
  10.     double temp;
  11.     bool done = false;
  12.     int lastIndex = 0;
  13.  
  14.     int arr[5] = {2,3,4,5,6};
  15.  
  16.       while (!done) {
  17.             lastIndex = 0;
  18.             for (int i = 0; i < count - 1; i++) {
  19.                   if (arr[i] % 2 != 0 && arr[i + 1] % 2 == 0) {
  20.                         temp = arr[i + 1];
  21.                         arr[i + 1] = arr[i];
  22.                         arr[i] = temp;
  23.                         break;
  24.                   } else {
  25.                         lastIndex++;
  26.                   }
  27.  
  28.                   if (lastIndex == count - 1) {
  29.                         done = true;
  30.                   }
  31.             }
  32.       }
  33.    
  34.       for (int x = 0; x < count; x++) {
  35.             cout << arr[x] << ", ";
  36.       }
  37.  
  38.       return 0;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top