Advertisement
Spocoman

06. Equal Arrays

Nov 17th, 2023
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     const int MAX_SIZE = 99;
  7.     int numbers1[MAX_SIZE]{};
  8.     int numbers2[MAX_SIZE]{};
  9.  
  10.     int arrSize, sum = 0;
  11.     cin >> arrSize;
  12.  
  13.     for (int i = 0; i < arrSize; i++) {
  14.         cin >> numbers1[i];
  15.     }
  16.  
  17.     for (int i = 0; i < arrSize; i++) {
  18.         cin >> numbers2[i];
  19.     }
  20.  
  21.     for (int i = 0; i < arrSize; i++) {
  22.         if (numbers1[i] != numbers2[i]) {
  23.             cout << "Arrays are not identical. Found difference at " << i << " index.\n";
  24.             return 0;
  25.         }
  26.         sum += numbers1[i];
  27.     }
  28.  
  29.     cout << "Arrays are identical. Sum: " << sum << endl;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement