Skip to content

Instantly share code, notes, and snippets.

@bavardage
Created January 27, 2010 23:21
Show Gist options
  • Select an option

  • Save bavardage/288268 to your computer and use it in GitHub Desktop.

Select an option

Save bavardage/288268 to your computer and use it in GitHub Desktop.
MODULE exp;
IMPORT Out;
PROCEDURE exponent*(x,n: INTEGER):INTEGER;
VAR
y,z,k: INTEGER;
BEGIN
y := 1;
z := x;
k := n;
WHILE k > 0 DO
WHILE k MOD 2 = 0 DO
z := z*z;
k := k DIV 2;
END;
IF k MOD 2 = 1 THEN
y := z*y;
k := k-1;
END;
END;
RETURN y;
END exponent;
BEGIN
Out.Int(exponent(13,8), 0);
END exp.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment