Challenge

Project 1 - Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory) using Linked List

#include <stdio.h>

#include <stdlib.h>

// Function to find the union of two sets

void unionSets(int set1[], int size1, int set2[], int size2) {

printf("Union of the sets: ");

// Print all elements of set1

for (int i = 0; i < size1; i++) {

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

}

// Print elements of set2 which are not in set1

for (int i = 0; i < size2; i++) {

int found = 0;

for (int j = 0; j < size1; j++) {

if (set2[i] == set1[j]) {

found = 1;

break;

}

}

if (!found) {

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

}

}

printf("\n");

}

// Function to find the intersection of two sets

void intersectionSets(int set1[], int size1, int set2[], int size2) {

printf("Intersection of the sets: ");

// Print common elements in set1 and set2

for (int i = 0; i < size1; i++) {

for (int j = 0; j < size2; j++) {

if (set1[i] == set2[j]) {

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

break;

}

}

}

printf("\n");

}

int main() {

int size1, size2;

// User input for the size of the first set

printf("Enter the number of elements in the first set: ");

scanf("%d", &size1);

int set1[size1];

// User input for the elements of the first set

printf("Enter the elements of the first set: ");

for (int i = 0; i < size1; i++) {

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

}

// User input for the size of the second set

printf("Enter the number of elements in the second set: ");

scanf("%d", &size2);

int set2[size2];

// User input for the elements of the second set

printf("Enter the elements of the second set: ");

for (int i = 0; i < size2; i++) {

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

}

// Perform union and intersection

unionSets(set1, size1, set2, size2);

intersectionSets(set1, size1, set2, size2);

return 0;

}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.