Advertisement
Sanlover

Untitled

Dec 4th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int summary = 0;
  7. int N;
  8.  
  9. cout << "Enter the amount of elements(N) = ";
  10. cin >> N;
  11.  
  12. for (int i = 0; i < N; i++)
  13. {
  14. if (i % 2 == 0)
  15. summary += i + 1;
  16. else
  17. summary += (i + 1) * (-1);
  18. }
  19.  
  20. cout << "Summary of N elements = " << summary;
  21.  
  22. return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement