Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int equivalentArray(int a[], int b[], int size_a, int size_b) {
- int result = 0, i, j, count_matches, count_missmatch = 0;
- int matching_numbers[size_a];
- for (i = 0, count_matches = 0; i < size_a; i++) { // check all values in the array 1
- for (j = 0; j < size_b; j++) { // compare the current value with all values inside array 2
- if (a[i] == b[j]) {
- count_matches++;
- matching_numbers[count_matches] = a[i];
- } else {
- count_missmatch++;
- }
- }
- }
- if (count_missmatch > 0 && (count_matches == size_a || count_matches == size_b)) {
- result = 1;
- }
- return result;
- }
- int main() {
- int i, size_1, size_2, comparison;
- printf("Enter the size of your 1st array: ");
- scanf("%d", &size_1);
- int array_1[size_1];
- printf("\nEnter array values\n");
- for (i = 0; i < size_1; i++) {
- printf("%d. array element: ", i+1);
- scanf("%d", &array_1[i]);
- }
- // enter the second array
- printf("\n\nEnter the size of your 2nd array: ");
- scanf("%d", &size_2);
- int array_2[size_2];
- printf("\nEnter array values\n");
- for (i = 0; i < size_2; i++) {
- printf("%d. array element: ", i+1);
- scanf("%d", &array_2[i]);
- }
- // compare the two arrays
- comparison = equivalentArray(array_1, array_2, size_1, size_2);
- printf("\nThe returned value = %d", comparison);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment