Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(2) Set operation: Union, Intersection and difference ?Problem description? Writ

ID: 3914662 • Letter: #

Question

(2) Set operation: Union, Intersection and difference
?Problem description? Write a program to demonstrate the union, intersection and difference operation of set. ?Basic requirements? ?(1) the set elements are limited to letters in lower case [‘a’..’z’]. ? ?Test data? ?(1)Set1="magazine"?Set2="paper"? ?Set1?Set2="aegimnprz"?Setl ?Set2="ae"?Set1-Set2="gimnz"? ?(2)Set1= " 012oper4a6tion89"?Set2="error data"? ?Set1?Set2="adeinoprt"?Setl ?Set2="aeort"?Set1-Set2="inp"? ?Hint for implementation? ?array can be used to represent the set. (2) Set operation: Union, Intersection and difference
?Problem description? Write a program to demonstrate the union, intersection and difference operation of set. ?Basic requirements? ?(1) the set elements are limited to letters in lower case [‘a’..’z’]. ? ?Test data? ?(1)Set1="magazine"?Set2="paper"? ?Set1?Set2="aegimnprz"?Setl ?Set2="ae"?Set1-Set2="gimnz"? ?(2)Set1= " 012oper4a6tion89"?Set2="error data"? ?Set1?Set2="adeinoprt"?Setl ?Set2="aeort"?Set1-Set2="inp"? ?Hint for implementation? ?array can be used to represent the set. (2) Set operation: Union, Intersection and difference
?Problem description? Write a program to demonstrate the union, intersection and difference operation of set. ?Basic requirements? ?(1) the set elements are limited to letters in lower case [‘a’..’z’]. ? ?Test data? ?(1)Set1="magazine"?Set2="paper"? ?Set1?Set2="aegimnprz"?Setl ?Set2="ae"?Set1-Set2="gimnz"? ?(2)Set1= " 012oper4a6tion89"?Set2="error data"? ?Set1?Set2="adeinoprt"?Setl ?Set2="aeort"?Set1-Set2="inp"? ?Hint for implementation? ?array can be used to represent the set.

Explanation / Answer

The program given is in c language. you can use any c compiler to run this program. it will run well.

Union and Intersection program:


#include<stdio.h>
void main()
{
int i,k=0,x[10],y[10],c[25],j,n,n1,d[25],f=0;
printf(" how many elements in SET 1:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf(" please enter the elements no %d",i+1);
scanf("%d",&x[i]);
}
printf(" how many elements in set 2:");
scanf("%d",&n1);
for(i=0;i<n1;i++)
{
printf(" please enter elements no %d",i+1);
scanf("%d",&y[i]);
}
for(i=0;i<n;i++)
{
c[k]=x[i];
k++;
}
for(i=0;i<n;i++)
{
for(j=0;j<n1;j++)
{
if(y[i]==x[j])
break;
}
if(j==n)
{
c[k]=y[i];
k++;
}
}
printf(" the union set is:{");
for(i=0;i<k;i++)
printf("%d",c[i]);
printf("} ");
for(j=0;j<n;j++)
{
for(i=0;i<n1;i++)
{
if(y[i]==x[j])
break;
}
if(i!=n1)
{
d[f]=y[i];
f++;
}
}
printf(" the intersection set is :{");
for(i=0;i<f;i++)
printf("%d",d[i]);
printf("}");
getch();
}

Difference of two sets program

void difference(int set1[],int set2[],int set3[])

{

int i,n;

n=set1[0];

set3[0]=0;

for(i=1;i<=n;i++)

if(!member(set2,set1[i]))

set3[++set3[0]]=set1[i];

}

Write the value of set1 and set2 that you want and you will get your result in set3.