Program to merge array in c
#include<stdio.h>
#include<conio.h>
void
main()
{
int
a[100],b[100],c[100],i,j,n1,n2,n,s,s1,ns,temp=0;
clrscr();
printf("********
MERGEING TWO ARRAY *********** \n\n");
printf("Size
of Array A:");
scanf("%d",&n1);
printf("\nEneter
the A array values:");
for(i=0;i<n1;i++)
{
scanf("%d",&a[i]);
}
printf("\n\n
Size of Array B:");
scanf("%d",&n2);
printf("\n
Eneter the B array value:");
for(i=0;i<n2;i++)
{
scanf("%d",&b[i]);
}
j=0;
n=n1+n2;
for(i=0;i<n;i++)
{
if(i<n1)
{
c[i]=a[i];
}
else
{
c[i]=b[j];
j++;
}
}
printf("\n
MERGEING TWO ARRAY \n");
for(i=0;i<n;i++)
{
printf("%d\t",c[i]);
}
printf("\n\n
**** AFTER MERGING DELETE DUPLICATE ARRAY **** \n");
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(c[i]==c[j])
{
for(s=j;s<n;s++)
{
c[s]=c[s+1];
}
n=n-1;
}
}
}
for(i=0;i<n;i++)
{printf("%d\t",c[i]);
}
getch();
}
Output:
********
MERGEING TWO ARRAY ***********
Size
of Array A:5
Eneter
the A array values:1
2
3
4
5
Size of Array B:4
Eneter the B array value:3
4
6
7
MERGEING TWO ARRAY
1 2
3 4 5
3 4 6
7
**** AFTER MERGING DELETE DUPLICATE ARRAY ****
1 2
3 4 5
6 7
No comments:
Post a Comment