Thread: 1D Arrays

  1. #1
    Registered User BB89's Avatar
    Join Date
    Sep 2009
    Location
    Dallas, Texas
    Posts
    72

    1D Arrays

    I am very new to arrays and programming in general.

    Question: Finding the intersection

    Code:
    #include <stdio.h>
    
    int main (void)
    {
        int A[] = {1, 2, 5};
        int B[] = {1, 5, 9, 10};
        int n, k, sum = 0;
    
        for( n = 1; n < 6; n++)
            for( k = 1; n < 10; k++)
            {
                if(n == k)
                {
                    sum += k;
                    printf("%d and %d are the intersection", sum, k);
                }
            }
    }


    I doubt this is anywhere close to being right. But I am looking for help, tips, etc...but I do not want the answer given to me.

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    What are your two arrays for? You never even ref A & B.

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Can you define what you mean by intersection? Are you after finding if an element resides in both arrays and then print out their placement within the array? I am not sure what your summation is for.

  4. #4
    Registered User BB89's Avatar
    Join Date
    Sep 2009
    Location
    Dallas, Texas
    Posts
    72
    Good question, i am not to sure. I know I need a loop but I how to incorporate A and B.


    slingerland3g: Yes, I am trying to find what is common in both arrays in this case it is {1, 5}. I not sure how to find it.

  5. #5
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    You will have to find out how your ints n and k relate to your arrays. Are they to represent the element placements within your array? Are you then needing to sum up those values when they match, meaning the value of that array element.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  2. Dynamic (Numeric) Arrays
    By DavidB in forum C++ Programming
    Replies: 5
    Last Post: 05-03-2006, 07:34 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  4. 1D and 2D Arrays
    By Rajin in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2005, 06:23 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM