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

/* Return a pointer to an array of two dynamically allocated arrays of ints.
   The first array contains the elements of the input array s that are
   at even indices.  The second array contains the elements of the input
   array s that are at odd indices.

   Do not allocate any more memory than necessary. You are not permitted
   to include math.h.  You can do the math with modulo arithmetic and integer
   division.
*/
int **split_array(const int *s, int length) {
	// the array containg the two pointers to the even and odd arrays
	int **complete_arr = malloc(sizeof(int*) * 2);
	// even array 
	int *even_indx = malloc(sizeof(int)*(length/2));
	// odd array 
	int *odd_indx = malloc(sizeof(int)*((length - 1)/2));
	for (int i = 0; i < length; i++) {
		if (i % 2 = 0) {
			even_indx[i] = s[i];
		}
		else {
			odd_indx[i] = s[i];
		}
	}
	complete_arr[0] = even_indx;
	complete_arr[1] = odd_indx;
	return complete_arr;
}

/* Return a pointer to an array of two dynamically allocated arrays of ints.
   The first array contains the elements of the input array s that are
   at even indices.  The second array contains the elements of the input
   array s that are at odd indices.

   Do not allocate any more memory than necessary. You are not permitted
   to include math.h.  You can do the math with modulo arithmetic and integer
   division.
*/