You can also approximate π by approximating the area bounded by a circular arc. Consider the following quarter circle: which has a radius r equal to two inches. From the formula for the area of a circle, you can easily determine that the area of the quarter circle should be π square inches. You can also approximate the area computationally by adding up the areas of a series of rectangles, where each rectangle has a fixed width and the height is chosen so that the circle passes through the midpoint of the top of the rectangle. For example, if you divide the area into 10 rectangles from left to right, you get the following diagram: The sum of the areas of the rectangles approximates the area of the quarter circle. The more rectangles there are, the closer the approximation. For each rectangle, the width w is a constant derived by dividing the radius by the number of rectangles. The height h, on the other hand, varies depending on the position of the rectangle. If the midpoint of the rectangle in the horizontal direction is given by x, the height of the rectangle can be computed using the distance formula h = √r–x The area of each rectangle is then simply h x w. Write a program to compute the area of the quarter circle by dividing it into 100 rectangles. |