Symmetric Difference etc.
#include
#include void main()
{
int i,j,k,p,ch,n1,n2,set1[10],set2[10], set3[20],flag;
char wish;
clrscr();
do
{
printf(“press 1 for union”);
printf(“\npress 2 for intersection”);
printf(“\npress 3 for subtraction”);
printf(“\n enter ur choice”);
scanf(“%d”,&ch);
switch(ch)
{
case 1://for union
printf(“\nenter the size of set1\n”);
scanf(“%d”,&n1);
printf(“enter the element of set1\n”);
for(i=0;i<n1;i++)
scanf(“%d”,&set1[i]);
printf(“enter the size of set2\n”);
scanf(“%d”,&n2);
printf(“enter the elements of set2\n”);
for(i=0;i<n2;i++)
scanf(“%d”,&set2[i]);
k=0;
for(i=0;i<n1;i++)
{
set3[k]=set1[i];
k++;
}
for(i=0;i<n2;i++)
{
flag=1;
for(j=0;j<n1;j++)
{
if(set2[i]==set1[j])
{
flag=0;
break;
}
}
if(flag==1)
{
set3[k]=set2[i];
k++;
}
}
p=k;
for(k=0;k <p;k++)
{
printf(” %d”,set3[k]);
}
break;
case 2: //for intersection
printf(“enter the size of sets1”);
scanf(“%d”,&n1);
printf(“enter the element of set1”);
for(i=0;i<n1;i++)
scanf(“%d”,&set1[i]);
printf(“enter the size of sets2”);
scanf(“%d”,&n2);
printf(“enter the elements of set2”);
for(i=0;i<n2;i++)
scanf(“%d”,&set2[i]);
k=0;
for(i=0;i<n2;i++)
{
flag=1;
for(j=0;j<n1;j++)
{
if(set2[i]==set1[j])
{
flag=0;
break;
}
}
if(flag==0)
{
set3[k]=set2[i];
k++;
}
}
p=k;
for(k=0;k <p;k++)
{
printf(” %d”,set3[k]);
}
break;
case 3://for subtraction
printf(“enter the size of sets1”);
scanf(“%d”,&n1);
printf(“enter the element of set1”);
for(i=0;i<n1;i++)
scanf(“%d”,&set1[i]);
printf(“enter the size of sets2”);
scanf(“%d”,&n2);
printf(“enter the elements of set2”);
for(i=0;i<n2;i++)
scanf(“%d”,&set2[i]);
k=0;
for(i=0;i<n1;i++)
{
flag=1;
for(j=0;j<n2;j++)
{
if(set1[i]==set2[j])
{
flag=0;
break;
}
}
if(flag==1)
{
set3[k]=set1[i];
k++;
}
}
p=k;
for(k=0;k <p;k++)
{
printf(” %d”,set3[k]);
}
break;
}
printf(“\n want to continue: “);
flushall();
scanf(“%c”,&wish);
}
while(wish!=’n’);
} //prg terminates
Leave a Reply