#include <stdio.h>
#include <stdlib.h>

int **split_array(const int *s, int length) {
    int num_even_indices;
    if (length % 2 == 0) {
        num_even_indices = length / 2;
    } else {
        num_even_indices = (length / 2) + 1;
    }

    int **arr = malloc(2 * sizeof(int*));
    arr[0] = malloc(num_even_indices * sizeof(int)); // Array for even indices
    arr[1] = malloc((length - num_even_indices) * sizeof(int)); // Array for odd indices

    int even_index;
    int odd_index;
    for (int i = 0; i < length; i++) {
        if (i % 2 == 0) {
            arr[0][even_index] = s[i];
            even_index += 1;
        } else {
            arr[1][odd_index] = s[i];
            odd_index += 1;
        }
    }

    return arr;
}


/* Return a pointer to an array of ints with size elements.
   - strs is an array of strings where each element is the string
     representation of an integer.
   - size is the size of the array
 */
int *build_array(char **strs, int size) {
    int *arr = malloc(size * sizeof(int));
    for (int i = 0; i < size; i++) {
        // Starting at i = 1 because argv[0] is not used.
        arr[i] = strtol(strs[i + 1], NULL, 10);
    }

    return arr;
}


int main(int argc, char **argv) {
    /* Replace the comments in the next two lines with the appropriate
       arguments.  Do not add any additional lines of code to the main
       function or make other changes.
     */
    int *full_array = build_array(argv, argc - 1);
    int **result = split_array(full_array, argc - 1); // Length of full_array is argc - 1 because it does not include argv[0].

    printf("Original array:\n");
    for (int i = 0; i < argc - 1; i++) {
        printf("%d ", full_array[i]);
    }
    printf("\n");

    printf("result[0]:\n");
    for (int i = 0; i < argc / 2; i++) {
        printf("%d ", result[0][i]);
    }
    printf("\n");

    printf("result[1]:\n");
    for (int i = 0; i < (argc - 1) / 2; i++) {
        printf("%d ", result[1][i]);
    }
    printf("\n");
    free(full_array);
    free(result[0]);
    free(result[1]);
    free(result);
    return 0;
}


Split input array into two arrays. The first array contains the elements of the input array that are at even indices. The second array contains the elements of the input array s that are at odd indices. Print the arrays.