Skip to content

Instantly share code, notes, and snippets.

@willeccles
Last active August 29, 2016 15:39
Show Gist options
  • Save willeccles/6abb69959343d2fa9b8bbdc82dd279a0 to your computer and use it in GitHub Desktop.
Save willeccles/6abb69959343d2fa9b8bbdc82dd279a0 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int place = 1;
int places = 100;
int main(int argc, char* argv[]) {
if (argc >= 3) {
places = atoi(argv[2]);
place = atoi(argv[1]);
}
else if (argc == 2)
place = atoi(argv[1]);
for (int i = 1; i <= places; i++) {
char* num = malloc(sizeof(char)*100);
sprintf(num, "%d", i);
char* suf = malloc(sizeof(char)*100);
if ((i >= 11 && i <= 13) ||
(i > 100 && (
(i-11)%100==0 ||
(i-12)%100==0 ||
(i-13)%100==0 ))) suf = "th";
else switch(num[strlen(num)-1]) {
case '1':
suf = "st";
break;
case '2':
suf = "nd";
break;
case '3':
suf = "rd";
break;
default:
suf = "th";
break;
}
if (i != place) printf("%d%s ", i, suf);
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment