**

i am tring to merge two array but every time its display first array proparly but in second array

its only display last element....thx....#
**

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],b[10],i,j,c,d,e;
clrscr();
printf("how many number in first array=");
scanf("%d",&c);
printf("how many number in second array=");
scanf("%d",&d);
printf("\nenter %d number for fist array\n",c);
for(i=1;i<=c;i++)
    {
    scanf("%d",&a[i]);
    }
printf("\nenter %d number for second array\n",d);
for(j=1;j<=d;j++)
    {
    scanf("%d",&b[j]);
    }
e=c+d;
for(i=c+1;i<=e;i++)
    {
    for(j=1;j<=d;j++)
        {
        a[i]=b[j];
        }
    }
printf("\nafter merge two array");
for(i=1;i<=e;i++)
    {
    printf("\t%d",a[i]);
    }
getch();
}

try

for(i=c+1;i<=e;i++)
{
 a[i]=b[i-c];
}

instead of

for(i=c+1;i<=e;i++)
{
  for(j=1;j<=d;j++)
  {
       a[i]=b[j];  // this sets a[i]=b[d] because all settings a[i]=b[j] with j<d are overwritten by next j
  }
}

Please be aware that in C arrays are zero based i.e. array a begins with a[0] until a[9] with your declaration.
You should check that c, d and e are small enough to fit the array sizes.
Use better (i.e. self-explaining) names for your variables

thx its work now....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.