I have created a program to a program that takes three sets A, B and U
(universal set).I have found A complement , B complement and A 
intersection B complement but when I combine the code to find the A' 
intersection B' it wont work plz guide me what I am doing wrong.

I am writing a code only for A' n B'.



#include <iostream.h>


int main ( )
        
{
                int num_a;
                cout<<"Enter the Number of elements of the set A\n";
                cin>>num_a;
                const arraysize = 100;

                        int a[arraysize];
                cout<<"Enter the elements of the set A\n";
 
                                        for (int  i = 0; i < num_a; 
i++)
                                        {
                                                cin>>a[i];
                                        }
                
                                                        
        cout<<"A = {";

                                                                
                for ( int j = 0; j < num_a; j++)
                                                                
                        {
                                                                
                        cout<<" "<<a[j]<<" ";
if ( j < num_a - 1)
{
        cout<<",";
}       
                                                                
                }
                                                                
                                                        
        cout<<"}\n\n";


// FOR SET B
        int b[arraysize];
                int num_b;
                cout<<"Enter the Number of elements of the set B\n";
                cin>>num_b;
                
                cout<<"Enter the elements of the set B\n";

                                        for ( i = 0; i < num_b; i++)
                                        {
                                                cin>>b[i];
                                        }
                
                                                        
        cout<<"B = {";

                                                                
                for (  j = 0; j < num_b; j++)
                                                                
                        {
                                                                
                        cout<<" "<<b[j]<<" ";
if ( j < num_b - 1)
{
        cout<<",";
}       
                                                                
                }
                                                                
                                                        
        cout<<"}\n\n";

// FOR UNIVERSAL SET 
                int num_u;
                cout<<"Enter the Number of elements of the set U\n";
                cin>>num_u;

                int u[arraysize];
                cout<<"Enter the elements of the set U\n";

                                        for (  i = 0; i < num_u; i++)
                                        {
                                                cin>>u[i];
                                        }
                
                                                        
        cout<<"U = {";

                                                                
                for (  j = 0; j < num_u; j++)
                                                                
                        {
                                                                
                        cout<<" "<<u[j]<<" ";
if ( j < num_u - 1)
{
        cout<<",";
}       
                                                                
                }
                                                                
                                                        
        cout<<"}\n\n";
{// Acomp intersection Bcomp
  int Acomp [arraysize];
    for (i=0;i< num_u; i++)
    {
      for(j=0; j< num_a; j++)
      {
      if(u[i]==a[j])
  
       {
       Acomp [i]=u[i];
       }
      }
         
    }
 
 for(i=0;i < num_u;i++)
 {
  if(u[i]!=Acomp[i])
  {
    int j=0;
    Acomp[j] = u[i];
    j++;
  }
 }
   
  int Bcomp[arraysize];
    for (i=0;i< num_u; i++)
    {
      for(j=0; j< num_b; j++)
      {
      if(u[i]==b[j])
  
       {
       Bcomp[i]=u[i];
       }
      }
         
    }
 
 for(i=0;i < num_u;i++)
 {
  if(u[i]!=Bcomp[i])
  {
    int k =0;
    Bcomp[k] = u[i];
    k++;
  }
 }
  cout<<"A'nB' = {"; 
  
  for ( i = 0; i < num_a; i++)
     {
       for ( j= 0; j< num_b; j++)
       {
           if ( Acomp[i] == Bcomp[j] )
          {
           int AnB[arraysize];
           int c=0;
           AnB [c] = Acomp[i];
            cout<<AnB[c]<<" ";
           c++;
          }
       }
     }
cout<<"}";
 }

return 0;
}

Reply via email to