home *** CD-ROM | disk | FTP | other *** search
/ 64'er Special 7 / 64er_Magazin_Sonderheft_07_86-07_1986_Markt__Technik_de_Side_A.d64 / dezimalbruch (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  3KB  |  127 lines

  1. 0 rem *********************************
  2. 1 rem *                               *
  3. 2 rem *    berechnung periodischer    *
  4. 3 rem *        dezimalbrueche         *
  5. 4 rem *                               *
  6. 5 rem *    bernhard filpe             *
  7. 6 rem *    langgasse 28               *
  8. 7 rem *    6733 hassloch              *
  9. 8 rem *                               *
  10. 9 rem *********************************
  11. 10 poke53280,6:poke53281,6:printchr$(147),chr$(14),chr$(8)
  12. 20 print"[194]erechnung periodischer [196]ezimalbrueche"
  13. 30 print"[163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163]"
  14. 40 print"[197]ingabebeispiel:"
  15. 45 print"                  [192][192][192]"
  16. 50 print"[218]u berechnen: 0.76351"
  17. 60 print"[197]ingabe     : 0.76351   [204]aenge 3"
  18. 70 print""
  19. 80 input"[196]ezimalbruch      : ";x$
  20. 90 input"[204]aenge der [208]eriode: ";l$
  21. 100 l=val(l$):ifl<>int(l)orl<1thener$="[197]ingabe der [208]eriode falsch":goto2000
  22. 105 if val(x$)=0thener$="[198]alsche [197]ingabe":goto2000
  23. 110 rem test auf korrekte eingabe
  24. 120 xl=len(x$)
  25. 130 for i=1toxl
  26. 140 t$=mid$(x$,i,1):t=val(t$)
  27. 150 if(t=>1)and(t<=9)thenfl=1:goto180
  28. 160 if t$="0"andfl=0then nu=nu+1:goto180
  29. 165 if t$="0"then180
  30. 170 if t$="."andpf=0thenfl=1:pf=1:pk=i:goto180
  31. 175 er$="[198]alsche [197]ingabe":el=i:goto2000
  32. 180 next
  33. 200 if fl then x$=mid$(x$,nu+1):pk=pk-nu
  34. 210 xl=len(x$)
  35. 220 if pf=0thener$="[196]ezimalpunkt fehlt":goto2000
  36. 230 if l>xl-pkthener$="[198]alsche [208]eriodenangabe":goto2000
  37. 250 print"[147][194]erechnung periodischer [196]ezimalbrueche"
  38. 260 print"[163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163]"
  39. 270 print"[196]ezimalbruch       : ";:ifpk=1thenprint"0";
  40. 275 printx$
  41. 280 print"[204]aenge der [208]eriode : ";l$
  42. 290 print
  43. 300 rem berechnung
  44. 310 n(1)=10^(xl-l-pk)
  45. 320 if pk=1thenv$=mid$(x$,2,xl-l-1):goto337
  46. 330 v$=mid$(x$,1,pk-1):vl=len(v$)
  47. 335 v$=v$+mid$(x$,pk+1,xl-vl-1-l)
  48. 337 z(1)=val(v$)
  49. 340 n(2)=10^(xl-pk)
  50. 350 z(2)=val(mid$(x$,xl-l+1)):ifz(2)=0thener$="[196]ezimalbruch trivial":goto2000
  51. 360 n(3)=1-10^(-l):z(3)=1
  52. 400 gosub3000
  53. 410 gosub4000:print
  54. 420 if z(1)=0then 450
  55. 430 g1=z(1):g2=n(1):gosub5000:rem ggt
  56. 440 z(1)=z(1)/gg:n(1)=n(1)/gg
  57. 450 z(2)=z(2)*z(3)
  58. 460 n(2)=n(2)*n(3)
  59. 510 g1=z(2):g2=n(2):gosub5000:rem ggt
  60. 520 z(2)=z(2)/gg:n(2)=n(2)/gg
  61. 530 gosub3000
  62. 540 if z(1)<>0thengosub4300
  63. 550 if z(1)=0thengosub4200:end
  64. 555 print
  65. 560 g1=n(1):g2=n(2):gosub5000
  66. 570 gg=n(1)*n(2)/gg:rem kgv
  67. 580 z(1)=z(1)*gg/n(1)
  68. 590 z(2)=z(2)*gg/n(2)
  69. 600 n(2)=gg:z(2)=z(1)+z(2)
  70. 610 g1=z(2):g2=n(2):gosub5000
  71. 620 z(2)=z(2)/gg:n(2)=n(2)/gg
  72. 630 gosub3000:gosub4200
  73. 700 end
  74. 2000 rem fehleranzeige
  75. 2010 print" ";er$;" "
  76. 2015 if el=0then2030
  77. 2017 print"";x$:if el=1thenprint"^":goto2030
  78. 2020 forj=1toi-1:print" ";:next:print"^"
  79. 2030 for w=1to1000:geta$:ifa$=""then next
  80. 2040 run
  81. 3000 rem ausgabe der errechneten werte
  82. 3005 z(1)=int(z(1)):z(2)=int(z(2)):n(1)=int(n(1)):n(2)=int(n(2))
  83. 3010 z1$=str$(z(1)):n1$=str$(n(1))
  84. 3020 z2$=str$(z(2)):n2$=str$(n(2))
  85. 3030 z3$="1":n3$=str$(n(3))
  86. 3040 l1=len(z1$):if l1<len(n1$)then l1=len(n1$)
  87. 3050 l2=len(z2$):if l2<len(n2$)then l2=len(n2$)
  88. 3060 l3=len(n3$)
  89. 3070 if l1>len(z1$)thenz1$=" "+z1$:goto3070
  90. 3080 if l1>len(n1$)thenn1$=" "+n1$:goto3080
  91. 3090 if l2>len(z2$)thenz2$=" "+z2$:goto3090
  92. 3100 if l2>len(n2$)thenn2$=" "+n2$:goto3100
  93. 3110 if l3>len(z3$)thenz3$=" "+z3$:goto3110
  94. 3120 n3$="0"+mid$(n3$,2)
  95. 3130 return
  96. 4000 print"  ";z1$;"   ";z2$;"   ";z3$
  97. 4010 print"= ";
  98. 4020 fori=1tol1:print"[192]";:next:print" + ";:fori=1tol2:print"[192]";:next:print" * ";
  99. 4030 for i=1tol3:print"[192]";:next:print
  100. 4040 print"  ";n1$;"   ";n2$;"   ";n3$
  101. 4050 return
  102. 4100 print"  ";z2$;"   ";z3$
  103. 4110 print"= ";
  104. 4120 fori=1tol2:print"[192]";:next:print" * ";
  105. 4130 for i=1tol3:print"[192]";:next:print
  106. 4140 print"  ";n2$;"   ";n3$
  107. 4150 return
  108. 4200 print"  ";z2$
  109. 4210 print"= ";
  110. 4230 for i=1tol2:print"[192]";:next:print
  111. 4240 print"  ";n2$
  112. 4250 return
  113. 4300 print"  ";z1$;"   ";z2$
  114. 4310 print"= ";
  115. 4320 fori=1tol1:print"[192]";:next:print" + ";
  116. 4330 for i=1tol2:print"[192]";:next:print
  117. 4340 print"  ";n1$;"   ";n2$
  118. 4350 return
  119. 5000 rem ggt
  120. 5010 g1=int(g1):g2=int(g2)
  121. 5020 if g1<g2thenhi=g1:g1=g2:g2=hi
  122. 5030 if g1/g2=int(g1/g2)thengg=g2:return
  123. 5040 q=g1/g2:ifq>20 then g1=g1-int(q-10)*g2
  124. 5050 if g1=g2thengg=g1:return
  125. 5060 if g1>g2theng1=int(g1-g2):goto5050
  126. 5070 g2=int(g2-g1):goto5050
  127.