1D Arrays

This is a discussion on 1D Arrays within the C Programming forums, part of the General Programming Boards category; I am very new to arrays and programming in general. Question: Finding the intersection Code: #include <stdio.h> int main (void) ...

1. 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. What are your two arrays for? You never even ref A & B.

3. 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. 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. 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.