Put even and odd elements of an array in two separate arrays

Put even and odd elements of an array in two separate arrays

Input:

1 2 3 4 5 6 7 8 9 10


Output:


Elements of array Even:

2 4 6 8 10

Elements of array Odd:

1 3 5 7 9

Implementation:



#include <stdio.h>
#include <stdlib.h>
int main(void) {
 int *a,*odd,*even;
 int n,j=0,k=0,i;
 scanf("%d",&n);
 
 a=(int*)malloc(sizeof(int)*1000000);
 odd=(int*)malloc(sizeof(int)*1000000);
 even=(int*)malloc(sizeof(int)*1000000);
 
 for(i=0;i<n;i++)
  scanf("%d",(a+i));
 
 for(i=0;i<n;i++)
 {
  if(*(a+i)&1)
   odd[j++]=*(a+i);
  else
   even[k++]=*(a+i);
 }
 
 printf("Elements of array even:\n");
 for(i=0;i<j;i++)
  printf("%d ",*(even+i));
 
 printf("\nElements of array odd:\n");
 for(i=0;i<k;i++)
  printf("%d ",*(odd+i));
  
 return 0;
}