Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <memory>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- template <typename T>
- T sum(T e) {
- unsigned long long n = 1;
- T s = -1.5;
- T a = -1.5;
- while (abs(a) > e) {
- n++;
- a = pow(-1, n) * (((2*n) +1)/(pow(n,3)*(n+1)));
- s += a;
- };
- return s;
- }
- int main() {
- double e = 0;
- cin >> e;
- if (e < 10e-7) {
- cout << fixed << setprecision(abs(log10(e))) << sum(float(e));
- }
- else {
- cout << fixed << setprecision(abs(log10(e))) << sum(double(e));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement