QUESTION:
Given two arrays. Find its union.
Input : Enter size of first array : 6 Enter the elements : 1 2 3 4 5 3 Enter size of second array : 4 Enter the elements : 1 2 7 5 OUTPUT : 1 2 3 4 5 7
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[100],c,d,i,j,k;
scanf("%d ",&c);
for(i=0;i<c;i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&d);
for(i=c;i<(c+d);i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<(c+d);i++)
{
for(j=0;j<=i;j++)
{
if(a[j]==a[i] && j!=i)
break;
else if(a[j]==a[i] && j==i)
printf("%d ",a[i]);
}
}
}
Comments
Post a Comment