Advertisement
felixnardella

moltiplicazioni (metodo karatsuba)

Jul 20th, 2022
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. 5 rem moltiplicazioni (metodo karatsuba) by felice nardella
  2. 10 printchr$(147)chr$(5)" moltiplicazioni in multiprecisione"
  3. 15 print:print"primo fattore (min 5 cifre e max 8)":inputn1
  4. 20 print:print"secondo fattore (min 5 cifre e max 8)":inputn2
  5. 25 a$=str$(n1):b$=str$(n2)
  6. 30 c1=len(a$):c2=len(b$)
  7. 35 ifc1<6orc2<6orc1>9orc2>9goto15
  8. 40 i1=c1-4:i2=c2-4
  9. 45 x(0)=val(right$(a$,4))
  10. 50 x(1)=val(left$(a$,i1))
  11. 55 y(0)=val(right$(b$,4))
  12. 60 y(1)=val(left$(b$,i2))
  13. 65 ifx(0)=0andy(0)=0goto170
  14. 70 ifx(0)=0thenx(0)=x(1):x(1)=0
  15. 75 ify(0)=0theny(0)=y(1):y(1)=0
  16. 80 c(0)=x(0)*y(0)
  17. 85 c(3)=(x(1)-x(0))*(y(1)-y(0))
  18. 90 c(2)=x(1)*y(1)
  19. 92 c(1)=c(0)+c(2)-c(3)
  20. 95 c0$=str$(c(0)):r0$=right$(c0$,4):iflen(r0$)=2thenr0$="000"+r0$
  21. 100 iflen(r0$)=3thenr0$="00"+r0$
  22. 105 iflen(r0$)=4andleft$(r0$,1)=" "thenr0$="0"+r0$
  23. 110 c0=len(c0$):i0=c0-4:ifi0>0thenl0$=left$(c0$,i0)
  24. 115 ifi0<=0thenl0$=""
  25. 120 c(1)=c(1)+val(l0$)
  26. 125 c1$=str$(c(1)):r1$=right$(c1$,4)
  27. 130 c1=len(c1$):i1=c1-4:ifi1>0thenl1$=left$(c1$,i1)
  28. 135 ifi1<=0thenl1$=""
  29. 140 c(2)=c(2)+val(l1$):c2$=str$(c(2)):ifc(2)=0thenc2$=""
  30. 145 ifc(2)<>0andlen(r1$)=2thenr1$="000"+r1$:goto160
  31. 150 ifc(2)<>0andlen(r1$)=3thenr1$="00"+r1$:goto160
  32. 155 ifc(2)<>0andlen(r1$)=4andleft$(r1$,1)=" "thenr1$="0"+r1$
  33. 160 gosub175:ifx(1)=0ory(1)=0thenr0$=r0$+"0000"
  34. 165 printc2$r1$r0$:goto180
  35. 170 gosub175:r=x(1)*y(1):r$=str$(r):printr$"00000000":goto180
  36. 175 print:print"il prodotto di"n1"*"n2"e':":return
  37. 180 print:print"vuoi continuare? (s/n)"
  38. 185 getv$:ifv$=""goto185
  39. 190 ifv$<>"s"thenend
  40. 195 clr:goto15
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement