What would you like to do?

C program for set union and intersection operations?

already exists.

Would you like to merge this question into it?

already exists as an alternate of this question.

Would you like to make it the primary and merge this question into it?

exists and is an alternate of .

#include<stdio.h>
#include<conio.h>
void Union(int set1[10],int set2[10],int m,int n);
void Intersection(int set1[10],int set2[10],int m,int n);
void main()
{
{
int a[10],b[10],m,n,i,j;
int ch;
clrscr();
printf("\nEnter the no of elements in first set:");
scanf("%d",&m);
printf("\nEnter the elements:");
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
printf("\nElement of First set:\n");
for(i=0;i<m;i++)
{
printf("\t%d",a[i]);
}

printf("\nEnter the no of elements in second set:");
scanf("%d",&n);
printf("\nEnter the elements:");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
}
printf("\nElement of second set\n");
for(i=0;i<n;i++)
{
printf("\t%d",b[i]);
}
while(1)
{
printf("\n\tMenu\n\n1.Union\n2.Intersection");
printf("\n3.exit");
printf("\nenter your choice:-");
scanf("%d",&ch);
switch(ch)
case 1:
union(a,b,m,n);
break;
case 2:
intersection(a,b,m,n);
break;
case 3:
exit(0);
}
getch();
}
}
void union(int a[10],int b[10],int m,int n)
{
int c[20],i,j,k=0,flag=0;
for(i=0;i<m;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("\nElement of resultant set\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
void intersection(int a[10],int b[10],int m,int n)
{
int c[20],i,j,k=0,flag=0;
for(i=0;i<m;i++)
{
flag=0;
for(j=0;j<n;j++)
{
if(a[i]==b[j])
{
flag=1;
break;
}
}
if(flag==1)
{
c[k]=a[i];
k++;
}
}
printf("\nElement of resultant set\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
14 people found this useful
Thanks for the feedback!

C program for the power operation?

WARNING: This program will not work for x power y where the resulting value is greater than 32767. Example: 10 power 10 will give you an incorrect value. #include int mai

What is the difference between union and intersect operations in SQL?

  * The UNION operator combines the output of two query expressions into a single result set. Query expressions are executed independently, and their output is combined in

Explain union and intersection of sets?

The union of two or more sets is a set containing all of the members in those sets. For example, the union of sets with members 1, 2, 3, and a set with members 3, 4, 5 is the

C program to find union of the given two set?

 #include   #include   void main()   {   int i,k=0,x[10],y[10],c[25],j,n,n1,d[25],f=0;   clrscr();   printf("\\n how many elements in SET 1:");  

What is union and intersection of sets?

Given any two sets, for instance, A={ai} and B={bi}, the union of the sets are the values that are contained in either A or B, whereas the intersection of the sets are the val

What is operator precedence in c programming?

Operator precedence is often associated with order of evaluation,  however order of evaluation and operator precedence are actually  undefined in C. Expressions may be evalu

Write a programme in C to find the union and intersection of two sets?

write a program to find union and inter section of two array   BY: SNDPLN | DATE: APRIL 18, 2011 | CATEGORIES: SOLVEDIFF /*************************/-P-7-/******************

Set operations that show union and intersection real world examples when using algebraic equations?

On a voyage to Atlantis, Ariel from The Little Mermaid decided to  pick up shells so that she could make necklaces for her mermaid  friends. She picked up 30 green shells, 3

Difference between Union and Set Intersection Operation?

union means to group the given sets. where as intersection means to pick out the common elements from the given sets. if set a has 1,2,3 elements and B has 1,2,3,4,5. then i
In Algebra

What is union and intersection of set?

Union: putting the elements of the sets together Intersection: getting the common elements of the sets Example: Set A={1,2,3} Set B={2,3,4,5} Union of Sets A&B= {1,2,3,4,5}
In Algebra

What are intersection sets and union sets?

Sets contain elements. The intersection of sets (represented by an upside-down 'U') is the list of elements that are common in both sets. The union of sets (represented by 'U'