Advertisement
JOHNYTHEWINNER

Odd/Even - for

Feb 2nd, 2020
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. # include <iostream>
  2. using namespace std;
  3. #include <iomanip>
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cin >> n;
  9.     int scoreeven = 0;
  10.     int scoreodd = 0;
  11.     int temp;
  12.     for (int i = 0; i < n; i = i++)
  13.     {
  14.         cin >> temp;
  15.         if (i % 2 == 0)
  16.         {
  17.             scoreeven += temp;
  18.         }
  19.         else
  20.         {
  21.             scoreodd += temp;
  22.         }
  23.     }
  24.     if (scoreeven != scoreodd)
  25.     {
  26.         cout << "No" << endl;
  27.         cout << "Diff = " << abs(scoreeven - scoreodd) << endl;
  28.     }
  29.     else
  30.     {
  31.         cout << "Yes" << endl;
  32.         cout << "Sum = " << scoreeven << endl;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement