mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-06 06:43:47 +00:00
Initial commit
This commit is contained in:
parent
dc1b3d5e74
commit
6f6317c320
4 changed files with 16 additions and 8 deletions
|
|
@ -60,7 +60,9 @@
|
|||
|
||||
static string CardinalToOrdinal(int number)
|
||||
{
|
||||
switch (number)
|
||||
int lastTwoDigits = number % 100;
|
||||
|
||||
switch (lastTwoDigits)
|
||||
{
|
||||
case 11: // special cases for 11th to 13th
|
||||
case 12:
|
||||
|
|
@ -68,6 +70,7 @@
|
|||
return $"{number}th";
|
||||
default:
|
||||
int lastDigit = number % 10;
|
||||
|
||||
string suffix = lastDigit switch
|
||||
{
|
||||
1 => "st",
|
||||
|
|
@ -75,13 +78,14 @@
|
|||
3 => "rd",
|
||||
_ => "th"
|
||||
};
|
||||
|
||||
return $"{number}{suffix}";
|
||||
}
|
||||
}
|
||||
|
||||
static void RunCardinalToOrdinal()
|
||||
{
|
||||
for (int number = 1; number <= 40; number++)
|
||||
for (int number = 1; number <= 1030; number++)
|
||||
{
|
||||
Write($"{CardinalToOrdinal(number)} ");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue