Write a recursive function that computes the set intersection of two integer arrays.


Difficulty level
This exercise is mostly suitable for students
int belong(int E,int arr[],int N)
{
	int i;
	for (i=0;i<N;i++)
		if (arr[i]==E)
			return 1;
	return 0;
}

void inter_rec(int T1[],int start,int end,int T2[],int N2,int T3[],int *N3)
{
	if (start<=end)
	{
		if (belong(T1[start],T2,N2)&& !belong(T1[start],T3,*N3))
		{
			T3[*N3]=T1[start];
			(*N3)++;
		}
		inter_rec(T1,start+1,end,T2,N2,T3,N3);
	}
}


void intersection(int T1[],int N1,int T2[],int N2,int T3[],int *N3)
{
	*N3=0;
	inter_rec(T1,0,N1-1,T2,N2,T3,N3);
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Deepest node of the binary tree