Advertisement
desislava_topuzakova

09. Left and Right Sum

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