Challenge

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

Ans- the c program to user can give input like two list od data and this program will give the output as the union and Intersection of these two lists :

#include<stdio.h>
#include<stdlib.h>

void printUnion(int arr1[], int arr2[], int m, int n)
// function prints union of arr1[] and arr2[]
// m is the number of elements in arr1[] and n is the number of elements in arr2[]
{
int i=0,j=0;
while(i<m && j<n)
{
if(arr1[i]<arr2[j])
printf("%d", arr1[i++]);
else if (arr2[j] < arr1[i])
printf("%d", arr2[j++]);
else {
printf("%d", arr2[j++]);
i++;
}
}
//print remaining elements of the larger array
while (i < m)
printf("%d", arr1[i++]);
while (j<n)
printf("%d", arr2[j++]);
}
int main()
{
int arr1[]={1,2,4,5,6};
int arr2[]={2,3,5,7};
int m = sizeof(arr1) / sizeof(arr1[0]);
int n = sizeof(arr2) / sizeof(arr2[0]);
printf("The union list of two numbers is:");
printUnion(arr1, arr2, m, n);
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.

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.