Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
53
Task/Number-names/XPL0/number-names.xpl0
Normal file
53
Task/Number-names/XPL0/number-names.xpl0
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
code ChOut=8, CrLf=9, Text=12;
|
||||
|
||||
proc NumName(Dev, Num); \Output integer Num in prose to device Dev
|
||||
int Dev, Num;
|
||||
int OneTbl, TenTbl, ThoTbl, ThoPwr, I, Quot;
|
||||
|
||||
proc Out999(N); \Output number in range 0..999 (0 does nothing)
|
||||
int N;
|
||||
int Huns, Tens, Ones;
|
||||
[Huns:= N/100; \0..9
|
||||
N:= rem(0); \0..99
|
||||
Tens:= N/10; \0..9
|
||||
Ones:= rem(0); \0..9
|
||||
if Huns # 0 then
|
||||
[Text(Dev, OneTbl(Huns)); \1..9
|
||||
Text(Dev, " hundred ")];
|
||||
if Tens >= 2 then
|
||||
[Text(Dev, TenTbl(Tens));
|
||||
if Ones # 0 then
|
||||
[ChOut(Dev, ^-); Text(Dev, OneTbl(Ones))];
|
||||
]
|
||||
else if N # 0 then Text(Dev, OneTbl(N)); \N = 1..19
|
||||
];
|
||||
|
||||
[if Num = 0 then [Text(Dev, "zero"); return];
|
||||
if Num < 0 then [Num:= -Num; Text(Dev, "minus ")];
|
||||
|
||||
OneTbl:=[0, "one", "two", "three", "four",
|
||||
"five", "six", "seven", "eight", "nine",
|
||||
"ten", "eleven", "twelve", "thirteen", "fourteen",
|
||||
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen"];
|
||||
TenTbl:=[0, 0, "twenty", "thirty", "forty",
|
||||
"fifty", "sixty", "seventy", "eighty", "ninety"];
|
||||
ThoTbl:=[" billion ", " million ", " thousand "];
|
||||
|
||||
ThoPwr:= 1000000000;
|
||||
for I:= 0 to 2 do
|
||||
[Quot:= Num/ThoPwr;
|
||||
Num:= rem(0);
|
||||
if Quot # 0 then
|
||||
[Out999(Quot); Text(Dev, ThoTbl(I))];
|
||||
ThoPwr:= ThoPwr/1000;
|
||||
];
|
||||
Out999(Num);
|
||||
];
|
||||
|
||||
[NumName(0, 0); CrLf(0);
|
||||
NumName(0, 13); CrLf(0);
|
||||
NumName(0, 789); CrLf(0);
|
||||
NumName(0, -604_001); CrLf(0);
|
||||
NumName(0, 1_000_000); CrLf(0);
|
||||
NumName(0, 1_234_567_890); CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue