Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <cmath>
- #include <iostream>
- #include <time.h>
- using namespace std;
- //quadratic simplifier
- long double quadP(long double& a, long double& b, long double& c){
- cout << "Numerator: " << -b - sqrt(b*b - 4*a*c) << endl;
- cout << "Denominator: " << 2*a << endl;
- return (-b - sqrt(b*b - 4*a*c))/(2*a);
- }
- //compute pi
- int main(){
- long runt = time(NULL);
- long double A, B, C, sides;
- //iterations
- long long i = pow(10, 3);
- //S(n) n=3
- long double S = 2;
- for (int n = 2; n < i; n++){
- //"animation"
- system("cls");
- cout << n << endl;
- cout << i << endl;
- //sides
- sides = pow(2, n);
- //Parameters
- A = 2 + 2 * cos(M_PI * (sides - 2) / sides);
- B = -4*S;
- C = S*S;
- cout<< "A: " << A << endl;
- cout<< "B: " << B << endl;
- cout<< "C: " << C << endl;
- cout<<"Descriminant: " << sqrt(B*B - 4*A*C)<<endl;
- A = quadP(A, B, C);
- cout<<"Quad Out: " << A << endl;
- S = S - 2*A;
- cout<< "Sides: " << sides*2<< endl;
- cout<< "Side Length = " << S <<endl;
- cout<< "N-gon perimeter = " << S*sides*2;
- cin.ignore();
- }
- cout << "\n" << S << "\n" << "Runtime: " << time(NULL) - runt << "sec";
- cin.ignore();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement