Topic:
Enter an array of integers to implement a function that adjusts the order of the numbers in the array so that all the odd digits in the array are in the first half of the array, and all the even digits are in the second half of the array.
#include <stdio.h> #include <stdlib.h>void move_arr (int &NBSP;ARR[],&NBSP;INT&NBSP;SZ) {int*left = arr;int*right = arr + sz - 1 ;while (left < right) {while (left < right) && (*left) % 2 == 1) {left++;} while ((left < right) && (*right) % 2 == 0) {right--;} if (left != right) {int tmp = *right;*right = *left;*left = tmp;left++;right--;}}} Int main () {int i = 0;int arr[] = { 5, 2, 3, 4, 1, 6 };move_arr (arr, sizeof (arr) / sizeof (*arr));for (i = 0; i < sizeof (arr) / sizeof (*arr); i++) {printf ("%d ", arr[i]);} printf ("\ n"); system ("pause"); return 0;}
Results ;
5 1 3 4 2 6
Please press any key to continue ...
Adjust array so that all odd numbers are in front of even numbers