fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_LENGTH = 100000;
  5.  
  6. int main() {
  7. int n, v[MAX_LENGTH + 1], sum_even_no = 0, sum_odd_no = 0;
  8. cin >> n;
  9. for (int i = 1; i <= n; ++i) {
  10. cin >> v[i];
  11. }
  12. int i = 1;
  13. while (i <= n) {
  14. if (i % 2 == 0) {
  15. sum_even_no += v[i];
  16. } else {
  17. sum_odd_no += v[i];
  18. }
  19. ++i;
  20. }
  21. cout << sum_even_no - sum_odd_no;
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty