Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,63 @@
|
|||
MODULE IntSqrt;
|
||||
|
||||
IMPORT IO;
|
||||
|
||||
(* Procedure to find integer square root of a 32-bit unsigned integer. *)
|
||||
PROCEDURE Isqrt( X : LONGCARD) : LONGCARD;
|
||||
VAR
|
||||
Xdiv4, q, r, s, z : LONGCARD;
|
||||
BEGIN
|
||||
Xdiv4 := X DIV 4;
|
||||
q := 1;
|
||||
WHILE q <= Xdiv4 DO q := 4*q; END;
|
||||
z := X;
|
||||
r := 0;
|
||||
REPEAT
|
||||
s := q + r;
|
||||
r := r DIV 2;
|
||||
IF z >= s THEN
|
||||
DEC(z, s);
|
||||
INC(r, q);
|
||||
END;
|
||||
q := q DIV 4;
|
||||
UNTIL q = 0;
|
||||
RETURN r;
|
||||
END Isqrt;
|
||||
|
||||
(* Main program *)
|
||||
CONST (* constants for Part 1 of the task *)
|
||||
Max_n = 65;
|
||||
NrPerLine = 22;
|
||||
VAR
|
||||
n : LONGCARD;
|
||||
arr_n, arr_i : ARRAY[0..NrPerLine - 1] OF LONGCARD; (* for display *)
|
||||
j, k : INTEGER;
|
||||
BEGIN
|
||||
(* Part 1 *)
|
||||
k := 0; (* index into arrays *)
|
||||
FOR n := 0 TO Max_n DO
|
||||
arr_n[k] := n;
|
||||
arr_i[k] := Isqrt(n);
|
||||
INC(k);
|
||||
IF (k = NrPerLine) OR (n = Max_n) THEN
|
||||
IO.WrStr( 'Number: ');
|
||||
FOR j := 0 TO k - 1 DO IO.WrLngCard(arr_n[j], 3); END;
|
||||
IO.WrLn();
|
||||
IO.WrStr( 'Isqrt: ');
|
||||
FOR j := 0 TO k - 1 DO IO.WrLngCard(arr_i[j], 3); END;
|
||||
IO.WrLn();
|
||||
k := 0;
|
||||
END;
|
||||
END;
|
||||
IO.WrLn();
|
||||
|
||||
(* Part 2 *)
|
||||
IO.WrStr( 'Isqrt of odd powers of 7'); IO.WrLn();
|
||||
n := 7;
|
||||
FOR k := 1 TO 11 BY 2 DO
|
||||
IF k > 1 THEN n := n*49; END;
|
||||
IO.WrInt( k, 2); IO.WrStr( ' --> ');
|
||||
IO.WrLngCard( n, 10); IO.WrStr(' --> ');
|
||||
IO.WrLngCard( Isqrt(n), 5); IO.WrLn();
|
||||
END;
|
||||
END IntSqrt.
|
||||
Loading…
Add table
Add a link
Reference in a new issue