Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double circle_pi(int rectangles)
- {
- /* creates and initializes the doubles the function will be using. */
- double width, awidth, radius = 2, height, x, area, tarea = 0;
- int i;
- /* will run this algorithm until i is less than rectangles. */
- for (i = 0; i < rectangles; i++)
- {
- width = radius / rectangles; /* sets the width */
- awidth = width / 2; /* gets the mid point of the first width */
- x = awidth + (i * width); /* gets the midpoint of the rectangle in use */
- height = sqrt((radius * radius) - (x * x)); /* calculates the height */
- area = width * height; /* calculates the area of a single rectangle */
- tarea = area + tarea; /* adds the rectangle area to a total */
- }
- return tarea; /* returns the value of approximated pi */
- }
Add Comment
Please, Sign In to add comment