Write a recursive function that determines whether all the elements of an integer array
T1 belong to another integer array T2.
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;
}
int subset_rec(int T1[],int start,int end,int T2[],int N2)
{
if (start<=end)
return (belong(T1[start],T2,N2) && subset_rec(T1,start+1,end,T2,N2));
return 1;
}
int subset(int T1[],int N1,int T2[],int N2)
{
return(subset_rec(T1,0,N1-1,T2,N2));
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Merge 2 sorted arrays using an iterative function