Revision e9dc85c9-7026-45b2-8c3d-b197c64c11ab - Code Golf Stack Exchange

# C - <strike>95</strike> 83 characters

 main(n,k){scanf("%d",&n);k=(n+9)%10;printf("%d%s\n",n,k<3?"st0円nd0円rd"+3*k:"th");}

Degolfed:

 main(n,k)
 {
 scanf("%d",&n);
 k=(n+9)%10; // xx1->0, xx2->1, xx3->2
 printf("%d%s\n",n,k<3?"st0円nd0円rd"+3*k:"th");
 }

We could do <code>k=(n-1)%10</code> instead of adding 9, but for n=0 we would get an incorrect behaviour,
because in C <code>(-1)%10</code> evaluates to -1, not 9.

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