fork(8) download
  1. #include <stdio.h>
  2.  
  3. int isSubset(int arr1[], int arr2[], int m, int n)
  4. {
  5. int i = 0;
  6. int j = 0;
  7. for (i=0; i<n; i++)
  8. {
  9. for (j = 0; j<m; j++)
  10. {
  11. if(arr2[i] == arr1[j])
  12. break;
  13. }
  14.  
  15. /* If the above inner loop was not broken at all then
  16.   arr2[i] is not present in arr1[] */
  17. if (j == m)
  18. return 0;
  19. }
  20.  
  21. /* If we reach here then all elements of arr2[]
  22.   are present in arr1[] */
  23. return 1;
  24. }
  25.  
  26. int main()
  27. {
  28. int arr1[] = {11, 1, 13, 21, 3, 7};
  29. int arr2[] = {11,2, 7, 1};
  30.  
  31. int m = sizeof(arr1)/sizeof(arr1[0]);
  32. int n = sizeof(arr2)/sizeof(arr2[0]);
  33.  
  34. if(isSubset(arr1, arr2, m, n))
  35. printf("arr2[] is subset of arr1[] ");
  36. else
  37. printf("arr2[] is not a subset of arr1[]");
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 2296KB
stdin
Standard input is empty
stdout
arr2[] is not a subset of arr1[]