#include <iostream> using namespace std; void PrintArray(int a[], int n) { for(int i = 0; i < n; ++i) cout << a[i] << " "; } int main() { int n, p1 = 0, p2 = 0; cin >> n; int a[n]; for(int i = 0; i < n; ++i) cin >> a[i]; while(p2 < n) { if(a[p2] % 2 == 0) { swap(a[p1], a[p2]); ++p1; } ++p2; } PrintArray(a, n); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter