N'th: Difference between revisions

2,190 bytes added ,  11 months ago
Added Algol W
(Added Algol W)
Line 431:
1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd
1024th 1025th
 
</pre>
 
=={{header|ALGOL W}}==
<syntaxhighlight lang="algolw">
begin % suffix number with st, nd, rd or th as appropriate %
 
string(2) procedure ordinalSuffix ( integer value number ) ;
begin
integer numberRem100;
numberRem100 := number rem 100;
if numberRem100 >= 10 and numberRem100 <= 20 then begin
% numbers in the range 10 .. 20 always have "th" %
"th"
end
else begin
% not in the range 10 .. 20, suffix is st, nd, rd or th %
% depending on the final digit %
integer numberRem10;
numberRem10 := number rem 10;
if numberRem10 = 1 then "st"
else if numberRem10 = 2 then "nd"
else if numberRem10 = 3 then "rd"
else "th"
end if_numberRem100_in_10_to_20__
end ordinalSuffix ;
 
% tests ordinalSuffix, displays the suffix for all numbers in from .. to %
procedure testSuffix ( integer value from, to ) ;
begin
integer count;
count := 0;
for testValue := from until to do begin
writeon( i_w := 4, s_w := 0, " ", testValue, ordinalSuffix( testValue ) );
count := count + 1;
if count rem 8 = 0 then write()
end for_testValue ;
if count rem 8 not = 0 then write();
write()
end testSuffix ;
 
begin % task %
testSuffix( 0, 25 );
testSuffix( 250, 265 );
testSuffix( 1000, 1025 )
end
end.
</syntaxhighlight>
{{out}}
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th
8th 9th 10th 11th 12th 13th 14th 15th
16th 17th 18th 19th 20th 21st 22nd 23rd
24th 25th
 
250th 251st 252nd 253rd 254th 255th 256th 257th
258th 259th 260th 261st 262nd 263rd 264th 265th
 
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th
1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th
1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd
1024th 1025th
 
</pre>
3,021

edits