answersLogoWhite

0


Best Answer

#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]);

}

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

#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:");

scanf("%d",&n);

for(i=0;i

{

printf("\n please enter the elements no %d",i+1);

scanf("%d",&x[i]);

}

printf("\n how many elements in set 2:");

scanf("%d",&n1);

for(i=0;i

{

printf("\n please enter elements no %d",i+1);

scanf("%d",&y[i]);

}

for(i=0;i

{

c[k]=x[i];

k++;

}

for(i=0;i

{

for(j=0;j

{

if(y[i]==x[j])

break;

}

if(j==n)

{

c[k]=y[i];

k++;

}

}

printf("\n the union set is:{");

for(i=0;i

printf("%d",c[i]);

printf("}\n");

for(j=0;j

{

for(i=0;i

{

if(y[i]==x[j])

break;

}

if(i!=n1)

{

d[f]=y[i];

f++;

}

}

printf("\n the intersection set is :{");

for(i=0;i

printf("%d",d[i]);

printf("}");

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

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

/*************************/-P-7-/***************************

NAME:-Nimbalkar Yogesh Dattatraya

Roll No:-452 Class:-F.Y.B.C.A

Program Name:-Wirte a progam to find union & inter section

of two st of integers(store it in tow array)

***********************************************************/

#include

#include

void main()

{

int a[5],b[5],c[10],d[10];

int i,j,k,f,x;

clrscr();

printf("n Enter element of set A=");

for(i=0;i<5;i++)

{

scanf("%d",&a[i]);

}

printf("n Enter element of set B=");

for(i=0;i<5;i++)

{

scanf("%d",&b[i]);

}

for(i=0;i<5;i++)

{

c[i]=a[i];

}

for(k=0;k<5;k++)

{

f=0;

for(j=0;j

{

if(b[k]==c[j])

{

f=1;

break;

}

}

if(f==0)

{

c[i]=b[k];

i++;

}

}

x=0;

for(k=0;k<5;k++)

{

f=0;

for(j=0;j<5;j++)

{

if(a[k]==b[j])

{

f=1;

break;

}

}

if(f==1)

{

d[x]=a[k];

x++;

}

}

printf("n Elements of A Union B={");

for(k=0;k

{

if(k==i-1)

printf("%d",c[k]);

else

printf("%d,",c[k]);

}

printf("}n");

printf("n Elements of A Inter section B={");

for(k=0;k

{

if(k==x-1)

printf("%d",d[k]);

else

printf("%d,",d[k]);

}

printf("}");

getch();

}

****************/-P-7-/************************

Out put:-

************************************************

Enter element of set A=1 2 3 4 5

Enter element of set B=3 4 5 6 7

Elements of A Union B={1,2,3,4,5,6,7}

Elements of A Inter section B={3,4,5}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a programme in C to find the union and intersection of two sets?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program to find intersection between two arrays?

#include&lt;stdio.h&gt;


How do you write c programme to find proper subset of a given string?

you can use strstr()


How can you find the center of a regular polygon?

You can find the intersection of the angle bisectors or the intersection of the perpendicular bisectors of each side.


How do you find the point of intersection of a parallelogram?

It would help to know "... the point of intersection of a parallelogram" and what!


Write a c program to generate student mark details using union and find total and average and grade?

write a c program to display marks,total,average,grade using union


Write a programme to find greater among two numbers in c plus plus?

You could use an if, but the ternary operator is especially compact for this purpose: result = a &gt; b ? a : b;


What do you find at the intersection of a plane and a line?

another point


Where can you find a programme that you can make graffitti writing?

www.graffiticreator.net/


I thought I un-installed a program that the computer insists is still there and how do I find it?

if you think that you have uninstall a programme but it is still there in your computer you need check in the programme files where you will see the list of programme .....


What do you find at the intersection of a plane an a line?

Unless the line is a subset of the plane, the intersection is a point.


How do you find the center of a circle?

it is the intersection of the medians of two cords!


What continent would you find Jamaica?

tv programme i think