title: How to find Cartesian Product of two sets
body: <p>I am trying to create a program which enables the user to calculate the difference and cartesian product of two given sets. I have been able to find the difference of sets.</p>
  
  <p>I am having trouble writing the code for calculating the cartesian product of two sets i.e. Set 1 = <code>1,2</code> &amp; Set 2 = <code>3,4</code></p>
  
  <p>The program I have written so far to calculate the calculations for difference and half for cartesian product is as follows:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  
  main() {
      int i, j, k, p, ch, n1, n2, set1[10], set2[10], set3[20], flag;
      int wish;
  
      printf("\n Enter the size of sets1 \n");
      scanf_s("%d", &amp;n1);
      printf("\n Enter the element of set1 \n");
      for (i = 0; i &lt; n1; i++)
          scanf_s("%d", &amp;set1[i]);
      printf("\n Enter the size of sets2 \n");
      scanf_s("%d", &amp;n2);
      printf("\n Enter the elements of set2 \n");
      for (i = 0; i &lt; n2; i++)
          scanf_s("%d", &amp;set2[i]);
  
      do {
          printf("\n Menu for set operations");
          printf("\n press 1 for DIFFERENCE");
          printf("\n press 2 for CARTESIAN PRODUCT");
          printf("\n Enter your Choice");
          scanf_s("%d", &amp;ch);
          switch (ch) {
            case 1://for difference
              k = 0;
              for (i = 0; i &lt; n1; i++) {
                  flag = 1;
                  for (j = 0; j &lt; n2; j++) {
                      if (set1[i] == set2[j]) {
                          flag = 0;
                          break;
                      }
                  }
                  if (flag == 1) {
                      set3[k] = set1[i];
                      k++;
                  }
              }
              p = k;
              for (k = 0; k &lt; p; k++) {
                  printf(" %d", set3[k]);
              }
              break;
  
            case 2: //for cartesian product 
              k = 0;
              for (i = 0; i &lt; n1; i++) {
                  flag = 1;
                  for (j = 0; j &lt; n2; j++) {
                  }
              }
          }
          printf("\n Do you want to continue(0/1)? ");
          scanf_s("%d", &amp;wish);
      } while (wish == 0);
      getch();
  }
  </code></pre>