Advertisement
oriolmarti97

[X47882] Suma els valors tals que el següent és parell

Apr 30th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     while (cin >>n) {
  8.         int ant;
  9.         cin >>ant;
  10.         int suma=0;
  11.         for (int i=1;i<n;++i) {
  12.             int act;
  13.             cin >>act;
  14.             if (act%2==0) suma+=ant;
  15.             ant=act;
  16.         }
  17.         cout <<suma<<endl;
  18.     }
  19. }
  20.  
  21. //By Patata
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement