Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Interesting Challenge
Message
From
30/08/1999 16:53:59
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00259328
Message ID:
00259405
Views:
16
Wow, this is completely different from how I approached it, but great, nonetheless. Recursion never even occurred to me.

>If I didn't have access to my numerical analysis books and no connection to the internet, and a no pressure to optimize the function, it would look something like this.
>
>
>nAnswer = sr(100,1,100)
>? "THE ANSWER:", nAnswer
>
>FUNCTION sr(pOrig,pLower,pUpper)
>* attempt to determine the square root by dividing the interval
>? pOrig, pLower, pUpper
>WAIT
>nMiddle = ((pUpper - pLower) / 2) + pLower
>
>DO CASE
>	CASE pOrig = nMiddle*nMiddle
>		RETURN nMiddle
>	CASE pOrig > nMiddle*nMiddle
>		RETURN sr(pOrig,nMiddle,pUpper)
>	CASE pOrig < nMiddle*nMiddle
>		RETURN sr(pOrig,pLower,nMiddle)
>	OTHERWISE
>		? "ERROR: an impossible result!"
>		RETURN 0
>ENDCASE
>RETURN
>
>
>
>>Write a function to calculate the square root of a number to a given number of decimal places. (Yes. I know, VFP has the SQRT function, but what would you do without it?)
Erik Moore
Clientelligence
Previous
Reply
Map
View

Click here to load this message in the networking platform