Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <climits>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int a[1000], n, S= 0 , x = 0, y = 0 ;
  10.  
  11. cin >> n ;
  12. for ( int i = 0 ; i < n ; i ++ )
  13. cin >> a[i] ;
  14. for ( int i =0 ; i <n ; i ++ )
  15. {
  16. if ( a [i ]% 2 ==0 )
  17. {
  18. x= i;
  19. break ;
  20. }
  21. }
  22. for ( int i = n ; i >= 0 ; i -- )
  23.  
  24. {
  25. if ( a[i]% 2 == 0 )
  26. {
  27. y = i;
  28. break ;
  29. }
  30. }
  31. for ( int i = x ; i <= y ; i ++ )
  32. {
  33. S+= a[i];
  34. }
  35.  
  36. cout << S ;
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement