Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#C#, 62 bytes#

C#, 62 bytes

n=>n+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");

Full program and verification:

using System;
namespace OutputOrdinalNumbers
{
 class Program
 {
 static void Main(string[] args)
 {
 Func<int,string>f= n=>n+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");
 
 for (int i=1; i<=124; i++)
 Console.WriteLine(f(i));
 }
 }
}

#C#, 62 bytes#

n=>n+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");

Full program and verification:

using System;
namespace OutputOrdinalNumbers
{
 class Program
 {
 static void Main(string[] args)
 {
 Func<int,string>f= n=>n+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");
 
 for (int i=1; i<=124; i++)
 Console.WriteLine(f(i));
 }
 }
}

C#, 62 bytes

n=>n+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");

Full program and verification:

using System;
namespace OutputOrdinalNumbers
{
 class Program
 {
 static void Main(string[] args)
 {
 Func<int,string>f= n=>n+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");
 
 for (int i=1; i<=124; i++)
 Console.WriteLine(f(i));
 }
 }
}
corrected typo
Source Link
adrianmp
  • 1.7k
  • 1
  • 10
  • 15

#C#, 62 bytes#

n=>n+""+n=>n+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");

Full program and verification:

using System;
namespace OutputOrdinalNumbers
{
 class Program
 {
 static void Main(string[] args)
 {
 Func<int,string>f= n=>n+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");
 
 for (int i=1; i<=124; i++)
 Console.WriteLine(f(i));
 }
 }
}

#C#, 62 bytes#

n=>n+""+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");

Full program and verification:

using System;
namespace OutputOrdinalNumbers
{
 class Program
 {
 static void Main(string[] args)
 {
 Func<int,string>f= n=>n+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");
 
 for (int i=1; i<=124; i++)
 Console.WriteLine(f(i));
 }
 }
}

#C#, 62 bytes#

n=>n+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");

Full program and verification:

using System;
namespace OutputOrdinalNumbers
{
 class Program
 {
 static void Main(string[] args)
 {
 Func<int,string>f= n=>n+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");
 
 for (int i=1; i<=124; i++)
 Console.WriteLine(f(i));
 }
 }
}
Source Link
adrianmp
  • 1.7k
  • 1
  • 10
  • 15

#C#, 62 bytes#

n=>n+""+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");

Full program and verification:

using System;
namespace OutputOrdinalNumbers
{
 class Program
 {
 static void Main(string[] args)
 {
 Func<int,string>f= n=>n+(n/10%10==1||(n%=10)<1||n>3?"th":n<2?"st":n<3?"nd":"rd");
 
 for (int i=1; i<=124; i++)
 Console.WriteLine(f(i));
 }
 }
}

AltStyle によって変換されたページ (->オリジナル) /