At 06:36 PM 12/16/98 -0200, you wrote:
>b) I have the function Sqr(x), that gives me the BASIC equivalent of
>x^2; how can I do a x^n(n<>2) in TP?
p := 1;
while n <> 0 do
begin
if n mod 2 = 1 then p := p * x;
n := n div 2;
x := sqr(x);
end;
After this is executed, variable p contains your answer.
Maybe you can speed things up by replacing "div 2" by "shr 1" and replacing
"mod 2" by "and 1".
Bye,
Maarten
****
MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED] and put
in the body (not subject) "unsubscribe msx [EMAIL PROTECTED]" (without the
quotes :-) Problems? contact [EMAIL PROTECTED] (www.stack.nl/~wiebe/mailinglist/)
****