Advertisement
Spocoman

09. Left and Right Sum

Sep 6th, 2023
1,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int num;
  7.     cin >> num;
  8.  
  9.     int number;
  10.  
  11.     int  leftSum = 0;
  12.     int rightSum = 0;
  13.  
  14.     for (int i = 0; i < num; i++)
  15.     {
  16.         cin >> number;
  17.         leftSum += number;
  18.     }
  19.  
  20.     for (int i = 0; i < num; i++)
  21.     {
  22.         cin >> number;
  23.         rightSum += number;
  24.     }
  25.        
  26.     if (leftSum == rightSum) {
  27.         cout << "Yes, sum = " << leftSum << endl;
  28.     }
  29.     else {
  30.         cout << "No, diff = " << abs(leftSum - rightSum) << endl;
  31.     }
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement