Advertisement
desislava_topuzakova

09. Left and Right Sum

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