home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 12
/
012.d81
/
gcd
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-08-26
|
2KB
|
57 lines
1 gosub50000
3 q$="[205][194][206]-"
5 z=7440:y=41261
6 w=9:pau=4
10 print"[147]"
1000 print"[147]find the greatest common divisor."
1010 print:print"give me two numbers in the format a,b or hit return for";
1011 print" an example."
1015 input">";a$,b$:a=val(a$):b=val(b$)
1020 iflen(a$)>11 or len(b$)>11 then10000
1021 ifa=0orb=0thena=z:b=y
1022 a=abs(a):b=abs(b)
1023 z=a:y=b
1024 printtab(13);a","b
1025 print
1030 x=a
1040 ifb<xthenx=b:b=a:a=x
1050 x=int(b/a)
1060 r=b-x*a
1061 printspc(12-len(str$(b)))
1065 printb" ="x" * "a" + "r
1070 ifr=0thengcd=a:goto1200
1080 b=a:a=r
1090 goto1050
1200 print:print"the greatest divisor is:"gcd
1202 print:print"the least common multiple is:"z*y/gcd:print
1203 print"";
1205 printtab(w);"[ ] touch any key [ ] q-quits";
1206 fori=1tolen(q$)
1207 poke783,peek(783)and253:poke781,22:poke782,w+1:sys65520:printmid$(q$,i,1);
1208 printspc(17)mid$(q$,len(q$)+1-i,1);:fors=0topau:ifpeek(197)<>64 then1210
1209 next:next:goto1206
1210 geta$:ifa$<>"q"then1000
1300 print"[147]bye.":fordl=1to500:nextdl
1305 print"[147]load"chr$(34)"presenter"chr$(34)",8":print"run"
1310 poke54296,0:poke631,13:poke632,13:poke65535,23:poke198,2:end
1400 :
10000 rem error routine
10010 print"[147]we have encountered an error."
10020 print"please be sure you are entering valid"
10030 print"values for the numbers requested."
10040 print"press <space bar> to continue."
10050 poke198,0:wait198,1:geta$:poke198,0:run
50000 t$=" ":c=0:c$="":print"[147]"chr$(142):poke53281,0
50030 printspc(7)""t$:printspc(7)" gcd [146]"
50051 printspc(7)""t$:print:printtab(18)"by"
50060 print:printspc(12)"bryan vekovius"
50061 print" translated to the c-64 by alan gardner"
50070 print:printspc(12)"copyright 1985"
50080 print:print:print:print" loadstar is not public domain."
50090 print:print" please respect the author's rights."
50100 print:print" press space bar to continue."
50110 forcc=1to48:getk$:ifk$=" "then50130
50120 ifcc=1thenprintmid$(c$,c+2,1)"[145][145]";:c=not(c)
50125 next:goto50100
50130 printc$:return