What will be the simplest program for intersection of two sets in c language ?
I have tried from many ways.. But still confusing its going too long. I am not getting the proper logic also. // C program to find intersection of // two sorted arrays #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[] = {1, 2, 4, 5, 6}; Â Â int arr2[] = {2, 3, 5, 7}; Â Â int m = sizeof(arr1)/sizeof(arr1[0]); Â Â int n = sizeof(arr2)/sizeof(arr2[0]); Â Â printIntersection(arr1, arr2, m, n); Â Â getchar(); Â Â return 0; https://code.sololearn.com/cNY7lCFd9p26/?ref=app