c program for set operations
04:07
/*Program for various operations on set.
Operations covered :
1)
Create() : for creating a new set with initial members
of
the set
2)
print() : diaplays all members of the set
3)
Union() : finds union of two sets, set1[] and
set2[] and
stores
the result in set3[]
4)
intersection() : finds intersection of two sets, set1[] and set2[]
and
stores the result in set3[]
5)
difference() :finds difference of two sets, set1[] and set2[]
and
stores the result in set3[]
6)
member() :function returns 1 or 0 ,depending onwhether
the
element
x belongs or not to a set.
7) symmdiff()
: Finds Symmetric difference of two sets
Representation of a set
-----------------------
A set is
representrd using an array of integers.
It may be
declared as:
int
set[30];
set[0] -
gives number of elements in a set.
set[1] to
set[29] are for storing set members.
Example :
A
set,[2,11,3,5 6],when represebted will appear as:
[5][2][3][5][6][11][
][ ][ ] <--- array set[]
0
1 2 3 4 5 6 7 8 <---
index
*/
//output >
1)Create
2)Print
3)Union
4)Intersection
5)Difference
6Symmetrec Difference
7)Quit
Enter Your Choice:1
Creting First Set*******
No. of elements in the set:3
enter set elements :5 3 2
Creating Second Set*****
No. of elements in the set:5
enter set elements :6 7 8 4 2
1)Create
2)Print
3)Union
4)Intersection
5)Difference
6Symmetrec
Difference
7)Quit
Enter Your Choice:3
Members of the set :-->5 3
2 6 7 8
4
press a
key............
1)Create
2)Print
3)Union
4)Intersection
5)Difference
6Symmetrec
Difference
7)Quit
Enter Your
Choice:4
Members of the set
:-->2
press a
key............
1)Create
2)Print
3)Union
4)Intersection
5)Difference
6Symmetrec
Difference
7)Quit
Enter Your
Choice:5
Members of the set :-->5
3
press a
key............
1)Create
2)Print
3)Union
4)Intersection
5)Difference
6Symmetrec Difference
7)Quit
Enter Your
Choice:6
Members of the set :-->5 3 6
7 8
4
press a
key............
1)Create
2)Print
3)Union
4)Intersection
5)Difference
6Symmetrec
Difference
7)Quit
Enter Your
Choice:7
press a key............
0 comments: