STANAANDREY

getE2

Dec 10th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int getE()
  5. {
  6.     int n, s = 1, e = 0;
  7.     cout << "n="; cin >> n;
  8.     for (int x = 2; x <= n * 2; x += 2, s = -s)
  9.     {
  10.         e += x * s;
  11.     }
  12.  
  13.    return e;
  14. }
  15.  
  16. int main()
  17. {
  18.     cout << getE();
  19.     return 0;
  20. }
Add Comment
Please, Sign In to add comment