fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. double sum = 0 , a_first, a_prev, a_cur;
  6. cin >> a_first;
  7. a_cur = a_first;
  8. a_prev = a_first;
  9.  
  10. while (a_cur >= 0) {
  11. cin >> a_cur;
  12. if (a_cur < 0) {
  13. sum += a_prev*a_first;
  14. break;
  15. }
  16. sum += a_prev*a_cur;
  17. a_prev = a_cur;
  18. }
  19.  
  20. cout << "Sum = " << sum << endl;
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 3432KB
stdin
-223
6 0 45 3 -1
2 3 4 -5
stdout
Sum = 0