The task: to arrange a static array (filled with random numbers) so that even and odd elements alternate in it, the difference is written to the end of the array. Functions do not use.
const int n = 10; int ar[n], ch[n], c2 = 0, c = 0, nch[n], k = 0, p = 0; for (int i = 0; i < n; i++) { ar[i] = rand() % 11; cout << ar[i] << "\t"; } cout << endl; for (int i = 0; i < n; i++) { if (ar[i] % 2 == 0) // если четное присваиваем массиву ch { ch[c] = ar[i]; c++; } else { nch[c2] = ar[i]; // если нечетное массиву nch c2++; } } if (c >= c2) // Если в нечетном цифр больше или поровну { for (int i = 0, j = 1; i < c2 * 2, j < c2 * 2; i += 2, j += 2) // похоже где-то cдесь что-то не то { ar[i] = ch[k]; ar[j] = nch[p]; k++; p++; } for (int i = c2; i < c; i++) // дописываем разницу { ar[i] = ch[i]; } for (int j = 0; j < n; j++) // вывод массива { cout << ar[j] << "\t"; } cout << endl << endl; k = 0; p = 0; } if (c2 > c) { for (int i = 0, j = 1; i < c * 2, j < c * 2; i += 2, j += 2) { ar[i] = ch[k]; ar[j] = nch[p]; k++; p++; } for (int i = c; i < c2; i++) { ar[i] = nch[i]; } for (int j = 0; j < n; j++) { cout << ar[j] << "\t"; } cout << endl << endl; }