Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <numbers>
- using namespace std;
- int main()
- {
- SetConsoleOutputCP(1251);
- double pi = { 3.14159 }, precision = { 0.001 }, s{}, calculated_pi{};
- unsigned long int n = 1;
- do {
- s += 1.0 / (pow(n, 2));
- calculated_pi = sqrt(6 * s);
- n++;
- }
- while (abs(calculated_pi - pi) >= precision);
- cout << "Обчислене значення пі: " << calculated_pi << endl;
- cout << "Кількість ітерацій, які виконалися: " << n << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement