C PROGRAMMING

write a c program to megre two arrays into third array

C program to merge two arrays into third array?

   #include<stdio.h>

main()
{
int aSize, bSize, mSize, i, j;
int a[10], b[10], Merged[20];

printf("n Please Enter the First Array Size : n");
scanf("%d", &aSize);

printf("nPlease Enter the First Array Elements : n");
for(i = 0; i < aSize; i++)
{
scanf("%d", &a[i]);
}
printf("n Please Enter the Second Array Size : n");
scanf("%d", &bSize);

printf("nPlease Enter the Second Array Elements : n");
for(i = 0; i < bSize; i++)
{
scanf("%d", &b[i]);
}

for(i = 0; i < aSize; i++)
{
Merged[i] = a[i];
}

mSize = aSize + bSize;

for(i = 0, j = aSize; j < mSize && i < bSize; i++, j++)
{
Merged[j] = b[i];
}

printf("nArray Elements After Merging n");
for(i = 0; i < mSize; i++)
{
printf(" %d t ",Merged[i]);
}

}

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button