Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- double factorial(double n) {
- if (n == 0) return 1;
- else return factorial(n - 1) * n;
- }
- int main() {
- cout.setf(ios::fixed);
- cout.precision(10);
- double n;
- while (cin >> n) {
- double total = 0;
- for (int i = 0; i < n; ++i) {
- total += (1/factorial(i));
- }
- cout << "With " << int(n) << " term(s) we get " << total << '.' << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement