Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4. bool isSubset(char *array1, char *array2, int n1, int n2){
  5. bool isS;
  6. for (int i = 0; i < n2; i++){
  7. isS = 0;
  8. for (int j = 0; j < n1;j++){
  9. if (array1[j] == array2[i]){
  10. isS = 1;
  11. }
  12. }
  13. if(isS == 0){
  14. return 0;
  15. }
  16. }
  17. if(isS == 1){
  18. return 1;
  19. }
  20. }
  21.  
  22. int main ()
  23. {
  24. int n1 = 0;
  25. int n2 = 0;
  26. printf ("Input the number of element(s) in the 1st array:\n");
  27. scanf ("%d", &n1);
  28. char *array1 = (char*)malloc(n1 * sizeof(char));
  29. printf ("Input the element(s) in 1st array:\n");
  30. for (int i = 0; i < n1; i++){
  31. scanf (" %c", &array1[i]);
  32. }
  33.  
  34. printf ("Input the number of element(s) in the 2nd array:\n");
  35. scanf ("%d", &n2);
  36. char *array2 = (char*)malloc(n2 * sizeof(char));
  37. printf ("Input the element(s) in 2nd array:\n");
  38. for (int j = 0; j < n2; j++){
  39. scanf (" %c", &array2[j]);
  40. }
  41. bool result = isSubset(array1,array2,n1,n2);
  42. if(result == 0){
  43. printf("False\n");
  44. }else{
  45. printf("True\n");
  46. }
  47. return 0;
  48. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement