Advertisement
myloyo

5.1.11

Nov 14th, 2022 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5. int main()
  6. {
  7.     int n, s, d;
  8.     cin >> n;
  9.     s = 0;
  10.     d = 1;
  11.     for (int i = 1; i <= n; i++) {
  12.         d *= i;
  13.         s += pow(-1, (i + 1)) * d;
  14.     }
  15.     cout << s;
  16. }
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement