+ 1

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

21st Jul 2018, 4:42 PM
Nikita Desale
Nikita Desale - avatar
11 Respostas
+ 3
Dnyaneshwari your code contains invalid characters, compiler doesn't know how to process these characters thus the compilation failure. These characters usually came from copy-paste text in web browser, view your code in a browser then you may see those characters.
22nd Jul 2018, 7:46 AM
Ipang
+ 2
I edit my Post .. And the code is included in the description
22nd Jul 2018, 6:18 AM
Nikita Desale
Nikita Desale - avatar
+ 2
Ok
22nd Jul 2018, 6:22 AM
Nikita Desale
Nikita Desale - avatar
+ 2
I have inserted the code
22nd Jul 2018, 6:25 AM
Nikita Desale
Nikita Desale - avatar
+ 2
Tell me the error message my friend?
22nd Jul 2018, 6:45 AM
Ipang
+ 1
Hello Dnyaneshwari can you include the code link in your question? you may get better chance if people can see what you have done so far. Alternatively add more explanation in the question e.g. what data is contained in these sets, how you implement the set behavior (uniqueness), and what ways have you tried which didn't succeeded.
22nd Jul 2018, 6:13 AM
Ipang
+ 1
Can you save it as code in Code Playground, that would be easier to look at and work with : )
22nd Jul 2018, 6:21 AM
Ipang
+ 1
Okay let me look at it first, understand though, I'm not giving you any promises, but I will help if I could : )
22nd Jul 2018, 6:26 AM
Ipang
+ 1
While executing.. Compiler showing me an error
22nd Jul 2018, 6:30 AM
Nikita Desale
Nikita Desale - avatar
+ 1
Its just compilation error
22nd Jul 2018, 6:50 AM
Nikita Desale
Nikita Desale - avatar
+ 1
Is the syntax is wrong or a logic?
22nd Jul 2018, 6:51 AM
Nikita Desale
Nikita Desale - avatar