Challenge

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

Project 1 Mathematical set theory:

#include<stdio.h>
int main()
{
int a[10],b[10],c[10],i,j,k=0,n1,n2;

// taking input set A

printf("\nEnter number of element of set A:");
scanf("%d",&n1);
printf("\nEnter the element of set A:");
for(i=0;i<n1;i++)
{
scanf("%d",&a[i]);
}
// taking input set B

printf("Enter number of element of set B\n");
scanf("%d",&n2);
printf("Enter the element of set B \n");
for(i=0;i<n2;i++)
{
scanf("%d",&b[i]);
}
//logic for Intersection
//copying set of A to set C
for(i=0;i<n1;i++)
{
for(j=0;j<n2;j++)
{
//finding the matched elements
if(a[i]==b[j])
{
c[k]=a[i];
k++;
}
}
}
//Printing intersection of set A and set B
printf("\n Intersection of set A and set B is :");
for(i=0;i<k;i++)
{
printf("%d\t", c[i]);
}
// logic for union

// copy the element of set A in set C
for(i=0;i<n1;i++)
{
// repeated element is not allowed so we check is any value repeated
for(j=0;j<k;j++)
{
if(c[j]==a[i])
break;
}
if(j==k) //if not repeated then store value in set c
{
c[k]=a[i];
k++;
}
}
// copy element of set B in set C
for(i=0;i<n2;i++)
{
// check for repeated element
for(j=0;j<k;j++)
{
if(c[j]==b[i])
break;
}
if(j==k) // if element is not repeated then store in set C
{
c[k]=b[i];
k++;
}
}

// printing of union of set A and set B
printf("\n Union of set A and B is:");
for(i=0;i<k;i++)
printf("%d\t",c[i]);
}

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.