Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <math.h>
- using namespace std;
- int main()
- {
- // ввод количества знаков
- int count;
- cout << "Сколько знаков после запятой вывести?: ";
- cin >> count;
- // вычисление числа pi
- cout << "Подождите, идёт вычисление числа Pi..." << endl;
- long double pi=0;
- for (int i = 0; i < 9999999; i++)
- {
- // ряд Лейбница
- pi += ( (pow(-1,i)) / (2*i + 1) );
- }
- pi *= 4;
- // выводим
- printf("%.*Lf",count,pi);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment