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

A logical operator representing the intersection of two sets?

There is no built-in logical operator that can achieve this.Logical operators operate upon Boolean operands (true and false)and output a Boolean value. Converting a set to a B

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 into a sin

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

What is union and intersection of sets?

Given any two sets, for instance, A={a i } and B={b i }, the union of the sets are the values that are contained in either A or B, whereas the intersection of the sets are t

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 topick up shells so that she could make necklaces for her mermaidfriends. She picked up 30 green shells, 35 blue

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

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}

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'

What is the union intersection set?

Given two or more sets there is a set which is their union and a set which is there intersection. But, there is no such thing as a "union intersection set", as required for th