Hi..
I have to create a code that will prompt the user to enter values for two int arrays. Each array is of length 5, with values such that 0 <= 'i' <= 99. Values entered for each array must be unique... The program will will compute the set intersection of the two arrays. That is, the program will display every value which the two arrays have in common.
For example, if array A = {5, 4, 3, 2, 1} and array B = {2, 4, 6, 8, 10} then their intersection is {2, 4}. If the two arrays have no common elements, the program should print a 'NULL SET' message. }
This is what I have created so far..
Code:
#include<stdio.h>
/* Function prints Intersection of arr1[] and arr2[]
m is the number of elements in arr1[]
n is the number of elements in arr2[] */
int print Intersection(int arr1[], int arr2[], int m, int n)
{
int i = 0, j = 0;
while(i < m && j < n)
{
if(arr1[i] < arr2[j])
i++;
else if(arr2[j] < arr1[i])
j++;
else /* if arr1[i] == arr2[j] */
{
printf(" %d ", arr2[j++]);
i++;
}
}
}
I cant quite figure out how to further represent the two arrays in my code. Can anyone please give me a hint or two? Am I on the right track? I have a very limited knowledge of C programming and a tutor was helping me before.. Unfortunately now that classes are over he doesnt come to our lab anymore. Thank you so much...