The document contains C code to find the union of two sets. It takes input for the number of elements and values of two sets A and B. It then copies the elements of set A into a new set C, checking for duplicates. It then copies elements of set B into C, again checking for duplicates. Finally, it prints out the union of sets A and B by printing all elements of set C.
The document contains C code to find the union of two sets. It takes input for the number of elements and values of two sets A and B. It then copies the elements of set A into a new set C, checking for duplicates. It then copies elements of set B into C, again checking for duplicates. Finally, it prints out the union of sets A and B by printing all elements of set C.
The document contains C code to find the union of two sets. It takes input for the number of elements and values of two sets A and B. It then copies the elements of set A into a new set C, checking for duplicates. It then copies elements of set B into C, again checking for duplicates. Finally, it prints out the union of sets A and B by printing all elements of set C.
h> #include<conio.h> void main() { int a[10],b[10],i,c[10],j,k=0,n1,n2;
// taking input set A
printf("Enter number of element of set A\n");
scanf("%d",&n1); printf("Enter the element of set A \n"); for(i=0;i<n1;i++) scanf("%d",&a[i]);
// taking input set B
printf("Enter number of element of set B\n");
scanf("%d",&n2); printf("Enter the element of set B \n"); for(i=0;i<n2;i++) scanf("%d",&b[i]);
// logic for calculate union
// copy the element of set A in set C
for(i=0;i<n1;i++) { // repeted element is not allowed so we check is any value repeted for(j=0;j<k;j++) { if(c[j]==a[i]) break; } if(j==k) //if not repesated then store value in set c { c[k]=a[i]; k++; } } // copy element of set B in set C for(i=0;i<n2;i++) { // check for repeted element for(j=0;j<k;j++) { if(c[j]==b[i]) break; } if(j==k) // if element is not repeted then store in set C { c[k]=b[i]; k++; } }
// printing of union of set A and set B
printf("Union of set A and B is:-\n"); for(i=0;i<k;i++) printf("%d ",c[i]); }