Lucian_Adrian

#491 Suma2

Dec 4th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int a[1001];
  6.  
  7. int main()
  8.  
  9. {
  10.  
  11. int n, i, p=-1, u=-1, s=0;
  12.  
  13. cin >> n;
  14.  
  15. for (i=1; i<=n; ++i)
  16.  
  17. {
  18.  
  19. cin >> a[i];
  20.  
  21. if (a[i]%2==0)
  22.  
  23. {
  24.  
  25. if (p==-1) {p=i; u=i;}
  26.  
  27. if (p!=-1) u=i;
  28.  
  29. }
  30.  
  31. }
  32.  
  33. if (p==-1) cout << "NU EXISTA";
  34.  
  35. else
  36.  
  37. {
  38.  
  39. for (i=p; i<=u; ++i) s+=a[i];
  40.  
  41. cout << s;
  42.  
  43. }
  44.  
  45. return 0;
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment