Sunday, 11 December 2011

Write a program to merged Array in c

#include
#include
#include
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;i100)
{
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 {
scanf("%d",&array2[i]);
}
for(i=0;i {
array3[i]=array1[i];
}
for(j=m,k=0;k {
array3[j]=array2[k];
}
p=m+n;
printf("The merged array is\n");
for(i=0;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