Thread: Help with arrays and intersections

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    2

    Help with arrays and intersections

    I am trying to find the intersection of 2 arrays... I have code written but cannot seem to find why it isn't working correctly... If someone could help a little bit that would be great,

    int main(int argc, _TCHAR* argv[])
    {
    getArray1;
    getArray2;
    getIntersection(Array1,Array2,Array3);
    printIntersection;



    return 0;
    }


    /************************************************** ************************************************** ***************
    Get Array1 and Array2 Function

    Input:
    Output: 2 Sets of 10 numbers
    ************************************************** ************************************************** ***************/

    void getTen(Array1, Array2)
    {
    int Array1[10];
    int Array2[10];
    int i=0;

    for(i=0;i<10;i++)
    printf("Enter 1st Array");
    scanf("%d",Array1[i]);
    printf("Enter 2nd Array");
    scanf("%d",Array2[i]);


    }


    /************************************************** ************************************************** ************
    Intersection Function

    Input: Array1 and Array2
    Output: Intersection number of Array1 and Array2
    ************************************************** ************************************************** ************/

    int findIntersection(int Intersection[]
    int i;
    int j;
    int k;
    getArray1();
    getArray2();


    for(i=0;i<10;i++)
    {
    for(j=0;j<10;j++)
    if(getArray1[i]==getArray2[j])
    {
    k++;
    }
    if (getArray1[i] != getArray2[j]);
    {

    }
    return k;
    }



    /************************************************** ************************************************** **********
    Print Intersection Function

    Input: The same numbers in Array1 and Array2
    Output: Printing numbers in the intersection array
    ************************************************** ************************************************** *********/
    void printIntersection(int Array3[10])
    {
    int i;

    for(i=0;i<10;i++)
    printf("%d\n", Array3[i]);}

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    As the sticky post “<< !! Posting Code? Read this First !! >>” notes, you need to use code tags when posting code.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    2
    Sorry Ive never used this before...

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code:
    #include <stdio.h>
    
    void getTen(int *);
    int findIntersection(int *Array1, int *Array2, int *Array3); 
    void printIntersection(int Array3[10], int k);
    
    int main(int argc, _TCHAR *argv[]) 
    {
      int num_intersec=0;
      int Array1[10], Array2[10], Array3[10];
      getTen(Array1);
      getTen(Array2);
      Array1[0] = 100;
      Array1[1] = 110;
      Array2[0] = 101;
      Array2[0] = 111;
      Array1[2] = 102;
      Array2[2] = 112;
      Array1[9] = 999;
      Array2[9] = 999;
      num_intersec = findIntersection(Array1,Array2, Array3);
      printIntersection(Array3, num_intersec);
    
      return 0;
    }
    /***************
    Input:
    Output: 2 Sets of 10 numbers
    ************/
    
    void getTen(int *Array)
    {
      int i;
    
      for(i=0;i<10;i++) {
        printf("Enter Ten  Array Integers \r");
        //scanf("%d",Array[i]);
        Array[i] = i;
      }
    }
    
    /************
    Intersection Function
    
    Input: Array1 and Array2
    Output: Intersection number of Array1 and Array2
    ***********/
    
    int findIntersection(int *Array1, int *Array2, int *Array3) {
      int i, j, k;
      for(i=0,k=0;i<10;i++)
      {
        for(j=0;j<10;j++) {
          if(Array1[i]==Array2[j])
          {
             Array3[k++] = Array2[j];
          }
        }
      }   
      return k;
    }
    
    /************
    Print Intersection Function
    
    Input: The same numbers in Array1 and Array2
    Output: Printing numbers in the intersection array
    *********/
    void printIntersection(int Array3[10], int k)
    {
      int i;
      printf("\n There are %d intersections\n", k);
      for(i=0;i<k;i++) {
          printf("%d\n", Array3[i]);
      }
    }
    Study up, and Welcome to the forum, ericasass!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PLEASE!!! help intersections problems
    By inmaterichard in forum C Programming
    Replies: 6
    Last Post: 07-24-2007, 05:14 PM