94./*Write
a program to merged Array*/
#include<stdio.h>
#include<conio.h>
#include<process.h>
main()
{
int
array1[100],array2[100],array3[200];
int i,j,k;
int m,n,p;
clrscr();
printf("How many elements you
want in first array:");
scanf("%d",&m);
if(m>100)
{
printf("Array out of bound,
press any key to exit...");
getch();
exit(1);
}
printf("Enter %d elements in
the first array:\n",m);
for(i=0;i<m;i++)
{
scanf("%d",&array1[i]);
}
printf("How many elements you
want is second array:");
scanf("%d",&n);
if(n>100)
{
printf("Array out of
bound,press any key to exit...");
getch();
exit(1);
}
printf("\nEnter %d elements
for the second array:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&array2[i]);
}
for(i=0;i<m;i++)
{
array3[i]=array1[i];
}
for(j=m,k=0;k<n;k++,j++)
{
array3[j]=array2[k];
}
p=m+n;
printf("The merged array
is\n");
for(i=0;i<p;i++)
{
printf("array3[%d]=%d\n",i,array3[i]);
}
getch();
}
OUTPUT
How many
elements you want in first array : 4
Enter 4
elements in the first array
1
3
5
7
How many
elements you want is second array : 4
Enter 4
elements for the second array
1
2
4
6
The merged
array is
array3[0] =
1
array3[0] =
3
array3[0] =
5
array3[0] =
7
array3[0] =
1
array3[0] =
2
array3[0] =
4
array3[0] =
6
No comments:
Post a Comment