I have an Array A[N]={1,2,3,4,5,6};
and I want to split it to 2 arrays of size N/2
such that B = 1, 2, 3 and C = 4, 5, 6
here is my program but there is something wrong with array C
Can you help me with it ?
#include <iostream.h>
void print(int X[], int newsize);
void main ()
{
int const N=6;
int A[N]={1,2,3,4,5,6};
int C[N/2],B[N/2];
for(int i =0;i<N;i++)
{
if(i>N/2)
{
int k=0;
C[k]=A[i];
k++;
}
else
B[i]=A[i];
}
print(B,N);
cout<<endl;
print(C,N);
}
void print(int X[],int size)
{
int newsize;
newsize=size/2;
for(int i=0;i<newsize;i++)
cout<<X[i]<<"\t";
}