I wan to merge two arrays but this code is not giving me the desired output.Can anyone plz point out the error?I applied this code on my own but cannot logically find any mistake.
int main()
int i,n,m;
int size;
printf(" enter the size of 1st array");
scanf(" %d",&n);
int a[n];
for(i=0;i<n;i++)
{
printf(" %d element is ",i);
scanf(" %d",&a[i]);
}
printf(" enter the size of 2nd array");
scanf(" %d",&m);
int b[m];
for(i=0;i<m;i++)
{
printf(" %d element is ",i);
scanf(" %d",&a[i]);
}
printf(" the merged array is");
int k;
int arr[size];
for(i=0;i<n;i++)
{
arr[i]=a[i];
}
size=m+n;
for(i=n,k=0;i<size && k<m;i++,k++)
{
arr[i]=b[k];
}
for(i=0;i<size;i++)
{
printf(" %d",arr[i]);
}
}
int arr[size];
,size
is used before initializing. May you can try movingsize=m+n;
beforeint arr[size];
. – H.S. Jul 15 '18 at 10:59