C Program to find union of two sets

Monday, 9 September 2013

#include<stdio.h>
#include<conio.h>
void main()
{
 int A[10],B[10],C[10],i,j,k=0,n,m,flag=0;
 clrscr();
 printf("Enter the size of array A");
 scanf("%d",&n);
 printf("Enter the element of First array A");
   for(i=0;i<n;i++)
     {
       scanf("%d",&A[i]);
     }
     printf("Enter the size of array B");
 scanf("%d",&m);
 printf("Enter the elements of array B");
   for(j=0;j<m;j++)
     {
       scanf("%d",&B[j]);
     }
for(i=0;i<n;i++)
 {
  C[k]=A[i];
  k++; }
for(i=0;i<n;i++)
 {
 flag=0;
  for(j=0;j<m;j++)
   {
    if(B[i]==C[j])
     {
     flag==1;
     break;
     }
   }
if(flag==0)
 {
  C[k]=B[i];
  k++;
 }}
printf("\n union\n");
for(i=0;i<k;i++)
{
printf("%d",C[i]);
}
getch();}
 
OUTPUT:-

1 comment

  1. #include
    void dubremove(int arr[],int n);
    void swaping(int x[],int m);
    int jl=0,arr[100],org[100],j2=0,n,m=0,i=0,j=0,t=0,org1[100],m1=0;
    void main()
    {
    int arr1[100],arr2[100],n1;
    printf("\nEnter the size of array\n");
    scanf("%d",&n1);
    printf("\nEnter the first array\n");
    for(i=0;i=2)
    org1[m1++]=arr[i];
    else
    org[m++]=arr[i];
    }
    }
    if(jl>=2)
    swaping(org1,m1);
    else
    swaping(org,m);
    jl++;
    }

    void swaping(int org[],int m)
    {
    for(i=0;iorg[j])
    {
    t=org[i];
    org[i]=org[j];
    org[j]=t;
    }
    }
    }
    if(j2>=2)
    {
    printf("\nResult of Union\n");
    for(j=0;j<m;j++)
    printf("%d ",org[j]);
    }
    j2++;
    }

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...
Related Posts Plugin for WordPress, Blogger...
 

Most Reading

Labels