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