 # C Programming Code Examples

## C > Arrays and Matrices Code Examples

### Put Even & Odd Elements of an Array in 2 Separate Arrays

``` Put Even & Odd Elements of an Array in 2 Separate Arrays This C Program puts even & odd elements of an array in 2 separate arrays. The program first finds the odd and even elements of the array. Then the odd elements of an array is stored in one array and even elements of an array is stored in another array. /* C Program to accept N integer number and store them in an array AR. The odd elements in the AR are copied into OAR and other elements are copied into EAR. Display the contents of OAR and EAR. */ #include <stdio.h> void main() { long int ARR, OAR, EAR; int x, j = 0, k = 0, n; printf("Enter the size of array AR \n"); scanf("%d", &n); printf("Enter the elements of the array \n"); for (x = 0; x < n; x++) { scanf("%ld", &ARR[x]); fflush(stdin); } /* Copy odd and even elements into their respective arrays */ for (x = 0; x < n; x++) { if (ARR[x] % 2 == 0) { EAR[j] = ARR[x]; j++; } else { OAR[k] = ARR[x]; k++; } } printf("The elements of OAR are \n"); for (x = 0; x < k; x++) { printf("%ld\n", OAR[x]); } printf("The elements of EAR are \n"); for (x = 0; x < j; x++) { printf("%ld\n", EAR[x]); } } ``` 