Advertisement
Guest User

pi

a guest
Dec 15th, 2013
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <cmath>
  3. #include <iostream>
  4. #include <time.h>
  5.  
  6. using namespace std;
  7.  
  8. //quadratic simplifier
  9.  
  10. long double quadP(long double& a, long double& b, long double& c){
  11.  
  12.     cout << "Numerator:    " << -b - sqrt(b*b - 4*a*c) << endl;
  13.     cout << "Denominator:  " << 2*a << endl;
  14.  
  15.  
  16.  
  17.     return (-b - sqrt(b*b - 4*a*c))/(2*a);
  18.  
  19. }
  20.  
  21. //compute pi
  22. int main(){
  23. long runt = time(NULL);
  24. long double A, B, C,  sides;
  25.  
  26. //iterations
  27. long long i = pow(10, 3);
  28.  
  29. //S(n) n=3
  30. long double S = 2;
  31.  
  32. for (int n = 2; n < i; n++){
  33.     //"animation"
  34.         system("cls");
  35.         cout << n << endl;
  36.         cout << i << endl;
  37.  
  38.     //sides
  39.     sides = pow(2, n);
  40.  
  41.     //Parameters
  42.     A = 2 + 2 * cos(M_PI * (sides - 2) / sides);
  43.     B = -4*S;
  44.     C = S*S;
  45.  
  46.     cout<< "A: " << A << endl;
  47.     cout<< "B: " << B << endl;
  48.     cout<< "C: " << C << endl;
  49.  
  50.     cout<<"Descriminant: " << sqrt(B*B - 4*A*C)<<endl;
  51.  
  52.     A = quadP(A, B, C);
  53.  
  54.     cout<<"Quad Out:     " << A << endl;
  55.    
  56.     S = S - 2*A;
  57.  
  58.     cout<< "Sides:            " << sides*2<< endl;
  59.     cout<< "Side Length =     " << S <<endl;
  60.     cout<< "N-gon perimeter = " << S*sides*2;
  61.  
  62.     cin.ignore();
  63.  
  64.     }
  65.  
  66. cout << "\n" << S << "\n" << "Runtime: " << time(NULL) - runt << "sec";
  67.  
  68. cin.ignore();
  69.  
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement