Hello

I'm trying to write a program which approximate the value of pi using the area of a quarter circle using rectangles. I wrote the program and it works fine, however the last 2 output( 100000 and 1000000 iterations) are not exactly the same as the one at the example.

Here is the code: Consider RADIUS as "2"

Code:double circle_pi(int rectangles) { double Width=RADIUS/(double)rectangles; double Height=0; double Area=0; double Pi=0; double x=0; x=Width/RADIUS; for( int i=0; i < rectangles; i++) { Height=sqrt((RADIUS*RADIUS)-(x*x)); Area=Width*Height; Pi+=Area; x+=Width; } return Pi; }

and the output is:

Approximations for pi

Iterations Circle Method

--------------------------------------…

1 3.464101615138

10 3.152411433262

100 3.141936857900

1000 3.141603544913

10000 3.141592998025

100000 3.141592664486

1000000 3.141592653923

and the example output:

Iterations Circle Method

--------------------------------------…

1 3.464101615138

10 3.152411433262

100 3.141936857900

1000 3.141603544913

10000 3.141592998025

100000 3.141592664482

1000000 3.141592653934