Advertisement
STANAANDREY

21d)met2

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