Write a c program that reads in two sets of numbers a and b


Sets of numbers can be represented using array of 0s and 1s. The idea is that a[i]!=0 if iis in the set, and a[i] == 0 if it is not. For example, the array a[10] = {0, 0, 1, 0, 1, 1, 0, 0, 0, 0}wouldrepresenttheset{2, 4, 5} becausea[2],a[4],anda[5] have the value 1, and everywhere else a contains zeros. Since the array has a fixed bound, say N, the values in the set are restricted to the range 0...N-1.

Write a C program that reads in two sets of numbers A and B, and calculates and print their union (AυB) and intersection (A∩B). (AυB) is the set of elements that appear in either A or B, and thatA∩B is the set of elements that appear in both A and B. The values in the sets are restricted to the range 0... 9.

1) Name your program sets.c.

2) The program will read in the number of element in the first set, for example, 4, then ?read in the numbers in the set, for example, 3 6 8 9. The repeat for the second set. The ?two sets do not necessarily are of the same size.

3) The sets are stored using arrays of 0s and 1s as described above.

4) Calculate the union and intersection of the two sets and display the result.

5) Sample input/output:

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Write a c program that reads in two sets of numbers a and b
Reference No:- TGS01275852

Now Priced at $30 (50% Discount)

Recommended (90%)

Rated (4.3/5)