Advertisement
Spocoman

01. Compare Arrays

Oct 27th, 2023 (edited)
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool areEqual(int arr1[], int length1, int arr2[], int lenght2) {
  6.     if (length1 != lenght2) {
  7.         return false;
  8.     }
  9.  
  10.     for (int i = 0; i < length1; i++) {
  11.         if (arr1[i] != arr2[i]) {
  12.             return false;
  13.         }
  14.     }
  15.     return true;
  16. }
  17.  
  18. int main() {
  19.     int length1, element, length2;
  20.     cin >> length1;
  21.  
  22.     int* arr1 = new int[length1];
  23.     for (int i = 0; i < length1; i++) {
  24.         cin >> element;
  25.         arr1[i] = element;
  26.     }
  27.  
  28.     cin >> length2;
  29.     int* arr2 = new int[length2];
  30.     for (int i = 0; i < length2; i++) {
  31.         cin >> element;
  32.         arr2[i] = element;
  33.     }
  34.  
  35.     cout << (areEqual(arr1, length1, arr2, length2) ? "equal" : "Not equal") << endl;
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement