home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 12 / 012.d81 / gcd (.txt) < prev    next >
Commodore BASIC  |  2022-08-26  |  2KB  |  57 lines

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