ZiGGi

pi calculator

Mar 6th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     // ввод количества знаков
  10.     int count;
  11.     cout << "Сколько знаков после запятой вывести?: ";
  12.     cin >> count;
  13.  
  14.     // вычисление числа pi
  15.     cout << "Подождите, идёт вычисление числа Pi..." << endl;
  16.     long double pi=0;
  17.     for (int i = 0; i < 9999999; i++)
  18.     {
  19.         // ряд Лейбница
  20.         pi += ( (pow(-1,i)) / (2*i + 1) );
  21.     }
  22.     pi *= 4;
  23.  
  24.     // выводим
  25.     printf("%.*Lf",count,pi);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment