bool isEven(int n) { return (n&1) == 0; } int gcd(int *a,int length) { int *pbegin = a; int *pend = a + length -1; while(pbegin < pend) { if (!isEven(*pbegin)) { pbegin++; continue; } if (isEven(*pend)) { pend--; continue; } int temp = *pbegin; *pbegin = *pend; *pend = temp; } return 0; } int main() { int a[10] = {2,4,9,6,1,8,4,5,6,7}; gcd(a,10); for (int i = 0;i <10;i++) { cout << a[i] <<endl; } return 0; }