I'm trying to figure this loop out but the output isn't showing because I keep making an infinite loop I think. Can anyone help me fix this?
Radius and error(not error_2) are user inputs. If the absolute value of the calculated error(error_2) is less than or equal to error, then area is considered the area. If not, loop to the width equation and increase n by 1.
It's supposed to find the area of a circle using rectangles. Its supposed to do these steps:
Initialize a variable called n to 1
Compute width of the rectangles as w=r / n
Compute the area by adding up the areas of all rectangles, as
area=4 x SIGMA(n on top and i=1 on bottom)〖w×√(r^2-(w×(i-1/2))^2 )〗
Compute the error
error=|area-π∙r^2 |
If the absolute value of error is less than or equal to the acceptable error entered by user then consider the current area value as close enough to be the real area of the circle. Otherwise, increase n by 1 and then loop to step 2.
Display the computed area, the absolute value of error, and the number of iterations it took to reach the solution.