Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "Russian");
- int i = 1, precision = 0;
- double e = -1, s = 0, a = 1.0 / 3.0;
- while (e <= 0) {
- cout << "Введите значение e (e > 0): ";
- cin >> e;
- }
- precision = -((int)log10(e) - 1); // Установка точности для вывода
- e = pow(10, -precision) / 2.000000000000001; // Упрощение E (0.008 -> 0.001 -> 0.000499..9)
- while(a > e) {
- a = pow(-1, i + 1) / pow(3, 2 * i - 1);
- s += a;
- i++;
- }
- printf("P: %.*lf\n", precision, s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement