Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,938 questions

51,875 answers

573 users

How to check if two arrays have the same set of digits in C

2 Answers

0 votes
#include <stdio.h>
#include <stdbool.h>

bool have_same_set_of_digits(int arr1[], int arr2[], int len1, int len2) {
    if (len1 != len2)
        return false;
  
    for (int i = 0; i < len1; i++) {
        bool found = false;
        for (int j = 0; j < len1; j++) {
            if (arr1[i] == arr2[j]) {
                found = true;
                break;
            }
        }
        if (!found)
            return false;
    }

    return true;
}
  
int main()
{
    int arr1[] = { 1, 3, 8, 5, 9, 2 };
    int arr2[] = { 2, 9, 1, 8, 2, 5 };
     
    int len1 = sizeof(arr1) / sizeof(int);
    int len2 = sizeof(arr2) / sizeof(int);
  
    if (have_same_set_of_digits(arr1, arr2, len1, len2))
        puts("Yes");
    else
        puts("No");
         
    return 0;
}
 
 
 
/*
run:
 
No
 
*/

 



answered Dec 4, 2020 by avibootz
0 votes
#include <stdio.h>
#include <string.h>
 
int main(void) {
    int arr1[] = { 1, 3, 8, 5, 9, 2 };
    int arr2[] = { 1, 3, 8, 5, 9, 2 };
     
    if (memcmp(arr1, arr2, 3 * sizeof(int)) == 0) {
        puts("Yes");
    } else {
        puts("No");
    }
    
    return 0;
}
 
 
   
   
/*
run:
   
Yes
   
*/

 



answered Dec 24, 2020 by avibootz
edited Dec 25, 2020 by avibootz

Related questions

...