Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Odd/Even - do/while

JOHNYTHEWINNER Feb 2nd, 2020 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # include <iostream>
  2. using namespace std;
  3. #include <iomanip>
  4. #include <math.h>
  5. #include <cmath>
  6. #include <string>
  7. int main()
  8. {
  9.     int n;
  10.     cin >> n;
  11.     int scoreeven = 0;
  12.     int scoreodd = 0;
  13.     int temp;
  14.     int i = 0;
  15.     do
  16.     {
  17.         cin >> temp;
  18.         if (i % 2 == 0)
  19.         {
  20.             scoreeven += temp;
  21.         }
  22.         else
  23.         {
  24.             scoreodd += temp;
  25.         }
  26.         i += 1;
  27.     } while (i <= n-1);
  28.     if (scoreeven != scoreodd)
  29.     {
  30.         cout << "No" << endl;
  31.         cout << "Diff = " << abs(scoreeven - scoreodd) << endl;
  32.     }
  33.     else
  34.     {
  35.         cout << "Yes" << endl;
  36.         cout << "Sum = " << scoreeven << endl;
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top