please convert the code toC language
//C++ program to check if two arrays//are equal or not
#include using namespace std;bool similar_array(vector arr1, vector arr2){ //create teo different hash table where for each key //the hash function is h(arr[i])=arr[i] //we will use stl map as hash table and //will keep frequency stored //so say two keys arr[0] and arr[5] are mapping to //the same location, then the location will have value 2 //instead of the keys itself //if two hash tables are exactly same then //we can say that our arrays are similar map hash1; map hash2; //for each number for (int i = 0, j = 0; i < arr1.size();="" i++,="" j++)=""> hash1[arr1[i]]++; hash2[arr2[i]]++; } //now check whether hash tables are exactly same or not for (auto it = hash1.begin(), ij = hash2.begin(); it != hash1.end() && ij != hash2.end(); it++, ij++) { if (it->first != ij->first || it->second != ij->second) return false; } //so ans will be updated maxdiff return true;}int main(){ int n, m; cout < "enter="" number="" of="" elements="" for="" array1="" &=""> cin >> n; //arrays having equal sum vector arr1(n, 0); vector arr2(n, 0); cout < "input="" the="" array=""> for (int i = 0; i < n;="" i++)=""> cin >> arr1[i]; cin >> arr2[i]; } if (similar_array(arr1, arr2)) cout < "the="" arrys="" are=""> else cout < "the="" arrys="" are="" not=""> return 0;}Output:Extracted text: Enter number of elements for array1 & array2 6 Input the array elements 1 2 1 3 2 1 2 2 3 1 1 1 The arrys are equal
bool similar_array(vector arr1, vector arr2){ //create teo different hash table where for each key //the hash function is h(arr[i])=arr[i] //we will use stl map as hash table and //will keep frequency stored //so say two keys arr[0] and arr[5] are mapping to //the same location, then the location will have value 2 //instead of the keys itself //if two hash tables are exactly same then //we can say that our arrays are similar map hash1; map hash2; //for each number for (int i = 0, j = 0; i < arr1.size();="" i++,="" j++)=""> hash1[arr1[i]]++; hash2[arr2[i]]++; } //now check whether hash tables are exactly same or not for (auto it = hash1.begin(), ij = hash2.begin(); it != hash1.end() && ij != hash2.end(); it++, ij++) { if (it->first != ij->first || it->second != ij->second) return false; } //so ans will be updated maxdiff return true;}int main(){ int n, m; cout < "enter="" number="" of="" elements="" for="" array1="" &=""> cin >> n; //arrays having equal sum vector arr1(n, 0); vector arr2(n, 0); cout < "input="" the="" array=""> for (int i = 0; i < n;="" i++)=""> cin >> arr1[i]; cin >> arr2[i]; } if (similar_array(arr1, arr2)) cout < "the="" arrys="" are=""> else cout < "the="" arrys="" are="" not=""> return 0;}Output:Extracted text: Enter number of elements for array1 & array2 6 Input the array elements 1 2 1 3 2 1 2 2 3 1 1 1 The arrys are equal
//for each number for (int i = 0, j = 0; i < arr1.size();="" i++,="" j++)=""> hash1[arr1[i]]++; hash2[arr2[i]]++; }
//now check whether hash tables are exactly same or not for (auto it = hash1.begin(), ij = hash2.begin(); it != hash1.end() && ij != hash2.end(); it++, ij++) { if (it->first != ij->first || it->second != ij->second) return false; }
//so ans will be updated maxdiff return true;}
int main(){ int n, m; cout < "enter="" number="" of="" elements="" for="" array1="" &=""> cin >> n;
//arrays having equal sum vector arr1(n, 0); vector arr2(n, 0); cout < "input="" the="" array=""> for (int i = 0; i < n;="" i++)=""> cin >> arr1[i]; cin >> arr2[i]; } if (similar_array(arr1, arr2)) cout < "the="" arrys="" are=""> else cout < "the="" arrys="" are="" not=""> return 0;}Output:Extracted text: Enter number of elements for array1 & array2 6 Input the array elements 1 2 1 3 2 1 2 2 3 1 1 1 The arrys are equal
for (int i = 0; i < n;="" i++)=""> cin >> arr1[i]; cin >> arr2[i]; } if (similar_array(arr1, arr2)) cout < "the="" arrys="" are=""> else cout < "the="" arrys="" are="" not="">
return 0;}
Output:
Extracted text: Enter number of elements for array1 & array2 6 Input the array elements 1 2 1 3 2 1 2 2 3 1 1 1 The arrys are equal
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here