Advertisement
Spocoman

05. Even and Odd Subtraction

Nov 17th, 2023
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     const int MAX_SIZE = 99;
  7.     int numbers[MAX_SIZE]{};
  8.  
  9.     int arrSize, diff = 0;
  10.     cin >> arrSize;
  11.  
  12.     for (int i = 0; i < arrSize; i++) {
  13.         cin >> numbers[i];
  14.     }
  15.  
  16.     for (int i = 0; i < arrSize; i++) {
  17.         diff += (numbers[i] % 2 == 0 ? numbers[i] : -numbers[i]);
  18.     }
  19.  
  20.     cout << diff << endl;
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement