Challenge

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

#include<stdio.h>

#define SIZE 50

int S1[SIZE],S2[SIZE],S3[SIZE];

void accept(int S[],int n)

{

int i;

for(i=1;i<=n;i++)

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

S[0]=n;

}

void display(int S[])

{

int n,i;

n=S[0];

printf("{");

for(i=1;i<=n;i++)

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

printf("}");

}

int ele_pre(int S[],int x)

{

int n,i;

n=S[0];

for(i=1;i<=n;i++)

if(S[i]==x)

return 0;

}

void set_union(int S1[],int S2[])

{

int n,i,m;

n=S1[0];

for(i=1;i<=n,i++)

S3[i]=S1[i];

m=S2[0];

for(i=1;i<=m;i++)

if(!ele_pre(S1,S2[i]))

S3[++n]=S2[i];

S3[0]=n;

}

void intersection(int S1[],int S2[])

{

int n,i,j=0;

n=S1[0];

for(i=1;i<=n;i++)

if(ele_pre(S2,S1[i]))

S3[++j]=S1[i];

S3[0]=j;

}

int main()

{

int n;

printf("\nprogram to perform the set operations");

printf("\nhow many elements for set-1");

scanf("%d",&n);

printf("\nenter the elements");

accept(S1,n);

printf("\nhow many elements in set-2");

scanf("%d",&n);

printf("\nenter the elements");

accept(S2,n);

set_union(S1,S2)

printf("\nS1 U S2=S3=");

display(S3);

intersection(S1,S2);

printf("\nS1 ^S2=S3=");

display(S3);

}

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.