One thing in the above version,
while (difference <= .1)
, the condition is the wrong way round, it should be
while (difference > .1)
I just had a go at this, and used a do-while loop, so that the condition is tested after the first pass.
But I am unsure on how to start the loop when the first time the old value isn't established. |
Just use a primitive estimate, assume the shape is a square rather than a circle, then
oldvalue = 4*radius*radius;
I'm less sure about the correctness of the mathematics, I worked this out from scratch using
x2 + y2 = radius2 and a method I'd previously tried for integration using rectangles.
My equations looked somewhat different to this:
|
square = (radius / n) * (sqrt((radius*radius) - (i*(radius / n)*(i*(radius / n)))));
|
I think that line may be wrong.
One other point, each time around the
while
loop,
newvalue
needs to be initialised to zero before using it to accumulate the total area.