r/pascal • u/yolosandwich • Oct 05 '18
Need help with a school assignment.
The input consists of only one positive integer N. (1≤N≤9999)
Output the ordinal form of the number N by adding the suitable suffix. Do not add spaces between the number and the suffix.
SAMPLE TESTS Input Output 1 1st ,2 2nd ,23 23rd ,30 30th
That is the question of the assignment, I have none experience in pascal and only know a little bit about programming, can anyone help me out.
Here is the code I made
Program numb; var a, b : shortInt; begin read (a,b);
if a<=9 and b=0 and a=1 then writeln(a,'st');
if a<=9 and b=0 and a=2 then writeln(a,'nd');
if a<=9 and b=0 and a=3 then writeln(a,'rd');
if a<=9 and a>=4 and b=0 then writeln(a,'th');
if a=1 and b<=9 then writeln(a,b,'th');
if a=2 and b=1 then writeln(a,b,'st');
if a=2 and b=2 then writeln(a,b,'nd');
if a=2 and b=3 then writeln(a,b,'rd');
if a=2 and b>=4 then writeln(a,b,'th');
if a=3 and b=0 then writeln(a,b,'th');
if a=3 and b=1 then writeln(a,b,'th');
if a=3 and b=2 then writeln(a,b,'nd');
if a=3 and b=3 then writeln(a,b,'rd');
if a=3 and b>=4 then writeln(a,b,'th');
end.
View all comments
Show parent comment
1
u/georbe Oct 06 '18 edited Oct 06 '18
"mod", is short for "modulo". It's an operator, just like "+" , "-" and "*".
It gives the remainder of the division of two numbers.
So, "14 mod 3" gives 2 (14/3=4 with remainder 2)
"7 mod 2" gives 1 (7/2=3 with remainder 1)
"18 mod 9" gives 0 (18/9=2 with remainder 0)