Spoken Numbers by koi

s(d){d&&putchar(32);}dd(d,l){char*t[]={"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thir","four","fif","six","seven","eigh","nine","twen","thir","for","fif","six","seven","eigh","nine"," thousand"," million"," billion"," hundred"};d>999&&dd(d/1000,l+1)+s(d%=1000);if(d)d>99&&dd(d/100,4)+s(d%=100),d>19&&printf("%sty",t[d/10+17])+s(d%=10),d&&printf("%s%s",t[d-1],"teen"+(d<13)*4),l&&printf(t[26+l]);}main(n){for(;scanf("%d",&n)>0;puts(""))dd(n,0);}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page