Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. int main()
  5. {
  6. int n;
  7. cout << "n="; cin >> n;
  8. int *a = new int[n];
  9. int i, s1, s2;
  10. s1 = s2 = 0;
  11. for (i = 0; i < n; i++)
  12. {
  13. cout << "a[" << i << "]="; cin >> a[i];
  14. }
  15. for (i = 0; i < n / 2; i++)
  16. if (a[i]>0)
  17. s1 = s1 + a[i];
  18. for (i = n / 2; i < n; i++)
  19. if (a[i] < 0)
  20. s2 = s2 + a[i];
  21. cout << "s1=" << s1 << endl;
  22. cout << "s2=" << s2<<endl;
  23. return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement