I have a quick question for anyone who has a couple of spare minutes..
I have created this program:
#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 printIntersection(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++;
}
}
}
int main()
{
int arr1[5] = {1, 2, 3, 4, 5};
int arr2[5] = {2, 7, 8, 9, 10};
int m = sizeof(arr1)/sizeof(arr1[0]);
int n = sizeof(arr2)/sizeof(arr2[0]);
printIntersection(arr1, arr2, m, n);
getchar();
return 0;
}
For this assignment,
DIRECTIONS: Write a program which 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.
Your program will will compute the set intersection of the
two arrays. That is, your 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, your program should print a 'NULL SET' message. }
EXAMPLES:
Enter five values: 1 2 3 4 5
Enter five values: 2 4 6 8 10
Intersection:2
Intersection:4
PROGRAM ENDS
Enter five values: 1 2 3 4 5
Enter five values: 6 7 8 9 10
Null Set
PROGRAM ENDS
Unfortunately I entered the example values into my code. Can anyone show me how to redo this correctly? My professor is asking for the student to be able to enter those values and the computer to evaluate the intersection.
Thank you!


Sign In
Create Account

Back to top









