Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int n;
- while (true) {
- cout << "Size of the Stack: ";
- cin >> n;
- int a[n];
- for (int i = 0; i < n; i++) {
- cout << "Enter a[" << i << "]: ";
- cin >> a[i];
- }
- for (int i = 0, j = n - 1; i < j;) {
- if (a[i] % 2 == 0) i++;
- if (a[j] % 2 == 0) j--;
- if (a[i] % 2 && a[j] % 2) {
- swap(a[i], a[j]);
- i++, j--;
- }
- }
- for (int i = 0; i < n; i++)
- cout << a[i] << " ";
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement