Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that computes a pair of estimates of , using a sequence of i

ID: 3733461 • Letter: W

Question

Write a C++ program that computes a pair of estimates of , using a sequence of inscribed and circumscribed regular polygons. Halt after no more than 30 steps, or when the difference between the perimeters of the circumscribed and inscribed polygons is less than a tolerance of =10¹. Your output should have three columns, for the number of sides, perimeter of inscribed polygon, and perimeter of circumscribed polygon. For the last two columns, display 14 digits after the decimal point. Your program and the output should appear in a Scientific Workplace document.

Explanation / Answer

As per your requirement the below one is solution please follow it

This is code ::

#include <iostream>
#include <cmath>

using namespace std;

#ifndef M_PI
#define M_PI (4.0 * std::atan2(1.0, 1.0))
#endif

int main() {
    int ngon = 3;
    double insngon = 0.0 ;
    double cirngon = 0.0;
    cout << "N" << " " << "ins-ngon" << " " << "cirngon" << " " << " ";
    while(ngon <= 30)
       {
           insngon = 2*ngon*sin(M_PI/ngon);
           cirngon = 2*ngon*tan(M_PI/ngon) ;
           printf("%d %.14lf %.14lf ",ngon,insngon,cirngon);
           ngon++;
           if(cirngon-insngon <= pow(10.0,-15)) break;
         
       }

  
}

inscribed area for r = 1 can be written as : n*sin(180/n) and circribed as n*tan(180/n)

Here radius is taken 1

These are outputs :

N           ins-ngon           cirngon      
3       5.19615242270663       10.39230484541326
4       5.65685424949238       8.00000000000000
5       5.87785252292473       7.26542528005361
6       6.00000000000000       6.92820323027551
7       6.07437234764581       6.74204466330540
8       6.12293491784144       6.62741699796952
9       6.15636257986204       6.55146421679164
10       6.18033988749895       6.49839392465813
11       6.19811625051145       6.45978284464407
12       6.21165708246050       6.43078061834694
13       6.22220727147650       6.40842443883141
14       6.23058615077680       6.39081728292420
15       6.23735072453278       6.37669685010066
16       6.24289030451610       6.36519575614906
17       6.24748360576339       6.35570150167122
18       6.25133439600949       6.34777130550474
19       6.25459443066789       6.34107847610298
20       6.25737860160923       6.33537761298145
21       6.25977517939933       6.33048142653085
22       6.26185288402455       6.32624493577883
23       6.26366585842734       6.32255447196749
24       6.26525722656248       6.31931988419500
25       6.26666167821521       6.31646892230541
26       6.26790737327680       6.31394312755755
27       6.26901736276243       6.31169478494024
28       6.27001066178524       6.30968463440622
29       6.27090306858862       6.30788013218868
30       6.27170779605921       6.30625411594059

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote