Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.7 kB
0
Indexable
Never
#include <stdio.h>

int findintersection(setA[],setB[])
{
    int i,j,setC[5];
    for(i=0;i<5;i++)
     {
         for(j=0;j<5;j++)
         {
             if(setA[i]==setB[j])
             {
               setC[i]=setA[i];
             }
         }
     }
     return(setC);
}

int main() {
    
    int setA[5],setB[5],i,j;
    
    printf("Enter values in first SET:");
    for(i=0;i<5;i++)
    {
        scanf("%d",&setA[i]);
    }
    
    printf("Enter values in second SET:");
    for(j=0;j<5;j++)
    {
        scanf("%d",&setB[j]);
    }
    
    printf("Values of first SET:");
    for(i=0;i<5;i++)
    {
        printf("%d /t",setA[i]);
    }
    
     printf("Values of second SET:");
    for(j=0;j<5;j++)
    {
        printf("%d /t",setA[j]);
    }
    
    do{
       
       int choice;
       printf("MENU/t 1.A-intersection-B /t 2.AUB /t 3.A-B /t 4.B-A /t");
       printf("Enter choice");
       scanf("%d",&choice);
       
       switch(choice)
       {
           case 1: int setC[5]=findintersection(setA,setB);
                  printf("A-intersection-B is:");
                  for(int i=0;i<5;i++)
                  {
                      printf("%d",setC[i]);
                  }
                  break;
                  
        case 2:int setD[5]=findintersection(setA,setB);
                   for(int i=0;i<5;i++)
                  {
                    setC[i]=setA[i]+setB[i];
                  }
                  
                  for(int i=0;i<5;i++)
                  {
                    setC[i]=setC[i]-setD[i];
                  }
                  printf("A-union-B is:");
                  for(int i=0;i<5;i++)
                  {
                      printf("%d",setC[i]);
                  }
                  break;
                  
        case 3: int setC[5];
                for(int i=0;i<5;i++)
                  {
                    setC[i]=setA[i]-setB[i];
                  }
                  printf("A-B is:");
                  for(int i=0;i<5;i++)
                  {
                      printf("%d",setC[i]);
                  }
                  break;
        
        case 4: int setC[5];
                for(int i=0;i<5;i++)
                  {
                    setC[i]=setB[i]-setA[i];
                  }
                  printf("B-A is:");
                  for(int i=0;i<5;i++)
                  {
                      printf("%d",setC[i]);
                  }
                  break;     
                  
        default:printf("INVALID CHOICE");
       }

    }while(choice<=4);
    
}