Guest User

Untitled

a guest
Jan 13th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. double circle_pi(int rectangles)
  2. {
  3. /* creates and initializes the doubles the function will be using. */
  4. double width, awidth, radius = 2, height, x, area, tarea = 0;
  5. int i;
  6. /* will run this algorithm until i is less than rectangles. */
  7. for (i = 0; i < rectangles; i++)
  8. {
  9. width = radius / rectangles; /* sets the width */
  10. awidth = width / 2; /* gets the mid point of the first width */
  11. x = awidth + (i * width); /* gets the midpoint of the rectangle in use */
  12. height = sqrt((radius * radius) - (x * x)); /* calculates the height */
  13. area = width * height; /* calculates the area of a single rectangle */
  14. tarea = area + tarea; /* adds the rectangle area to a total */
  15. }
  16. return tarea; /* returns the value of approximated pi */
  17. }
Add Comment
Please, Sign In to add comment