Advertisement
evage

Untitled

Nov 19th, 2021
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cout << "enter number of elements\n"; cin >> n;
  8.     vector<int> ar(n);
  9.     for (int i = 0; i < n; ++i) cin >> ar[i];
  10.  
  11.     long long sum = 0;
  12.     for (int i = 0; i < n; ++i)
  13.     {
  14.         if (ar[i] % 2 == 0)
  15.         {
  16.             sum += ar[i];
  17.             printf("num: %12d| pos: %d\n", ar[i], i + 1);
  18.         }
  19.     }
  20.     cout << "sum = " << sum;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement