Number names: Difference between revisions
Content added Content deleted
No edit summary |
(Added Commodore BASIC) |
||
Line 1,420: | Line 1,420: | ||
four trillion, one hundred twenty-three million, seven thousand, nine hundred thirteen |
four trillion, one hundred twenty-three million, seven thousand, nine hundred thirteen |
||
</pre> |
</pre> |
||
=={{header|Commodore BASIC}}== |
|||
Same as the Applesoft BASIC, except that one program line was too long for input, so it was moved into a small subroutine. Also added a word-wrap routine since 40 columns on most Commodores fills up quick. |
|||
<lang commodorebasicv2>10 print chr$(147);:input "give me a number";n |
|||
20 gosub 100 |
|||
25 print |
|||
30 gosub 400:print r$ |
|||
40 end |
|||
100 rem number name |
|||
110 if r$="" then for i=0 to 10:read s$(i),t$(i),u$(i),v$(i):next |
|||
120 if n=0 then r$="zero":return |
|||
130 r$="":d=10:c=100:m=1e3 |
|||
140 a=abs(n) |
|||
150 for u=0 to d |
|||
160 h=a-c*int(a/c) |
|||
170 if h>0 and h<d then r$=s$(h)+" "+r$ |
|||
180 if h>9 and h<20 then r$=t$(h - d)+" "+r$ |
|||
190 if h>19 and h<c then gosub 300 |
|||
200 h=a-m*int(a/m) |
|||
210 h=int(h/c) |
|||
220 if h then r$=s$(h)+" hundred "+r$ |
|||
230 a=int(a/m) |
|||
240 if a>0 then h=a-m*int(a/m):if h then r$=v$(u)+" "+r$ |
|||
250 if a>0 then next u |
|||
260 if n<0 then r$="negative "+r$ |
|||
270 return |
|||
280 data "","ten","","thousand" |
|||
281 data "one","eleven","","million" |
|||
282 data "two","twelve","twenty","billion" |
|||
283 data "three","thirteen","thirty","trillion" |
|||
284 data "four","fourteen","forty","quadrillion" |
|||
285 data "five","fifteen","fifty","quintillion" |
|||
286 data "six","sixteen","sixty","sextillion" |
|||
287 data "seven","seventeen","seventy","septillion" |
|||
288 data "eight","eighteen","eighty","octillion" |
|||
289 data "nine","nineteen","ninety","nonillion" |
|||
290 data "","","","decillion" |
|||
300 s=h-d*int(h/d) |
|||
305 r$=u$(int(h/d))+mid$("-"+chr$(0),1+abs(s=0),1)+s$(s)+" "+r$ |
|||
310 return |
|||
400 rem word-wrap string |
|||
401 tp$=r$ |
|||
405 if len(tp$)<=39 then goto 440 |
|||
410 for i=0 to 38:c$=mid$(tp$,39-i,1) |
|||
420 if s$<>" " then next i |
|||
430 as$=as$+left$(tp$,39-i)+chr$(13):tp$=mid$(tp$,40-i,len(tp$)):i=0:goto 405 |
|||
440 as$=as$+tp$ |
|||
450 r$=as$:return</lang> |
|||
{{out}} |
|||
<pre> |
|||
give me a number? 1234567890 |
|||
one billion two-hundred thirty-four |
|||
million five hundred sixty-seven |
|||
thousand eight hundred ninety. |
|||
ready. |
|||
█ |
|||
</pre> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |