/*
  evensAndOdds.c
  This function takes a pointer to an array and the length of the array as input and
  returns an array only involving the even elements of the array

  by Ismail Ari
  Phys494 Applied Fourier Analysis
  Bogazici University
  September 20, 2007

 *=================================================================*/
#include <stdio.h>
#include <malloc.h> /* required for allocation operations */

double *evens(double *x, int len) {
	double *result;
	int i;

	/* Allocate the memory for the result */
	result = malloc(sizeof(double) * len/2);

	for( i=0; i<len/2; i++) {
		result[i] = x[2*i]; /* Traverse the even elements of the array and assign */
	}

	return result;
}

double *odds(double *x, int len) {
	double *result;

	/* COMPLETE THE CODE HERE */

	return result;
}

int main() {
	double x[8] = {0,1,2,3,4,5,6,7};
	double *evensOfX, *oddsOfX;
	int i;

	evensOfX = evens(x,8);
	/* oddsOfX = odds(x,8); */


	/* Print the results */
	printf("evens: ");
	for( i=0;i<4; i++)
		printf("%.2lf ", evensOfX[i]);

	/*printf("\nodds: ")
	for( i=0;i<4; i++)
		printf("%lf", oddsOfX[i])*/

	return 0;
}