Challenge

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

Q.1)

Ans.

#include

    #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[],intx)

       {

       int n,i;

       n=S[0];

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

       if(s[i]==x)

       return 1;

       return 0;

       }

        void set_union(ints1[],ints2[])

       {

        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(s1s2[i]))

         s3[0]=n;

         }

         void intersection(ints1[],ints2[])

         {

          int n,i,j=0

          n=s1{0];

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

          if(ele_pre(s2s1[i]))

          s3[++j]=s1[i];

          s3[0]=j;

          }

           int main()

          {

           int n;

           printf("----------------------------------------------------------")

           printf("nProgram to perform the set operation.")

           printf("n----------------------------------------------------------")

           printf("nHow many elementfor set-1)

           scanf("%D",&n);

           printf("nEnter elementsn");

           accept(s1,n);

           printf("nHow many elemnt for set-2);

           scanf("%d",&n);

           printf("nEnter elementsn");

           accept(s1,n);

           printf("nHowmany element for set-2");

           scanf("%d",&n);

           printf("nEnter elementsn);

           accept(s2n);

           set_union(s1s2);

           printf("ns1U s2= s3=");

           display(s3);

           intersection(s1s2);

           printf("nS1^s2=s3=");

           display(s3);

           printf("n---------------------------------------------------------------n");

          }

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.