Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
42
Task/Digital-root/Modula-3/digital-root.mod3
Normal file
42
Task/Digital-root/Modula-3/digital-root.mod3
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
MODULE DigitalRoot EXPORTS Main;
|
||||
|
||||
IMPORT IO;
|
||||
FROM Fmt IMPORT F,LongInt;
|
||||
|
||||
TYPE
|
||||
Root = RECORD persistence,R:LONGINT END;
|
||||
|
||||
VAR
|
||||
R:Root;
|
||||
Arr:ARRAY[0..3] OF LONGINT := ARRAY OF LONGINT{627615L,
|
||||
39390L,
|
||||
588225L,
|
||||
393900588225L};
|
||||
|
||||
PROCEDURE DigitalRoot(InRoot,Base:LONGINT):Root =
|
||||
VAR
|
||||
r,persistence,Num:LONGINT;
|
||||
BEGIN
|
||||
r := ABS(InRoot);
|
||||
persistence := 0L;
|
||||
WHILE r >= Base DO
|
||||
Num := r;
|
||||
r := 0L;
|
||||
WHILE Num # 0L DO
|
||||
r := r + (Num MOD Base);
|
||||
Num := Num DIV Base;
|
||||
END;
|
||||
INC(persistence);
|
||||
END;
|
||||
RETURN Root{persistence, r};
|
||||
END DigitalRoot;
|
||||
|
||||
BEGIN
|
||||
FOR I := FIRST(Arr) TO LAST(Arr) DO
|
||||
R := DigitalRoot(Arr[I], 10L);
|
||||
IO.Put(F(LongInt(Arr[I]) &
|
||||
" has additive persistence %s and digital root of %s\n",
|
||||
LongInt(R.persistence),
|
||||
LongInt(R.R)));
|
||||
END;
|
||||
END DigitalRoot.
|
||||
Loading…
Add table
Add a link
Reference in a new issue