#include <iostream>using namespace std;int main(int argc, char const *argv []) { int n, fact = 1; double out = 0; cout << "Input n: "; cin >> n; for(int i = 1, j = 2; i <= n; i++, j++) { double temp = i; fact *= j; temp /= fact; if (i%2 == 0) out -= temp; else out += temp; } cout << "Result: " << out << endl; return 0; }
Comments