Find Union and Intersection of Two Sets C Program

By | October 8, 2016

Learn how to perform Set Operations using Functions in C Programming Language. This C program to find union and intersection of Two Arrays with Functions takes two different arrays as input from the user for Set A and Set B. The intersection elements and union elements elements are stored in different arrays.

What is a Set?

A set is a collection of distinct objects or elements. It is therefore, a well defined collection of distinct elements. The union of set A and B is represented by A ∪ B, and it will form a resultant set which consists of all the elements of sets A and B without any repetition. The intersection of set A and B is represented by A ∩ B, and it forms a resultant set that consists of the common elements from the sets A and B.

This code for calculation intersection and union requires the arrays containing set elements to be in sorted order. If they are not in sorted order, then there will be a problem in fetching the union of the two sets.

Example of Union and Intersection of Two Arrays

A = {1, 2, 3, 4, 5, 6}

B = {4, 5, 6, 7, 8, 9}

Union: (A ∪ B) = {1, 2, 3, 4, 5, 6, 7, 8, 9}

Intersection: (A ∩ B) = {4, 5, 6}

Must Read: C Program To Find Value of Arithmetic Expression

 

C Program For Set Operations using Functions – Union and Intersection Methods

 

Output

C Program For Set Operations using Functions to Find Union and Intersection of Two Arrays

If you get any compilation errors or have any doubts in this C program to find union and intersection of two Sets, let us know about it in the comment section below.

2 thoughts on “Find Union and Intersection of Two Sets C Program

  1. Vedant Mishra

    Why is it important to sort the array to find union of two sets in C?

    Reply

Let's Discuss