Abt. Lange Integerzahlen halbieren
======================
Anm.d.Verf.: Das Ganze soll nur eine Vorbereitung auf die russische Multiplikationsmethode werden.
Code
if 0
$MAKE CL
endif
WindowTitle "Langzahl halbieren"
Windowstyle 1048
Window 0,0-%maxx,%maxy-42
font 2
randomize
declare m$,c$,c%,a%,r%,a$,tm&,vz%,anz%,manuell%
eingabe:
print "\n Bitte Lange Integerzahl eingeben [<return> für Zufall]: ";
input m$
if m$=""
m$=if(rnd(2),chr$(45)," ") +chr$(49+rnd(9))
anz%=1024+rnd(6000)
whileloop 2,anz%
m$=m$+chr$(48+rnd(10))
endwhile
cls
print m$
else
manuell%=1
endif
nochmal:
anz%=len(m$)
tm&=&gettickcount
m$=trim$(m$)
if left$(m$,1)="-"
vz%=-1
m$=mid$(m$,2,len(m$)-1)
endif
r%=0
a$=""
whileloop len(m$)
c$ = mid$(m$,&loop,1)
c%=10*r%+val(c$)
a%=c%\2
a$=a$+str$(a%)
r%=c%-2*a%
endwhile
a$=a$+":"
a$=translate$(a$,"0"," ")
a$=trim$(a$)
a$=translate$(a$," ","0")
a$=left$(a$,len(a$)-1)
if vz%= -1
a$="-"+a$
endif
locate 1,1
' print
' case r% mod 2:a$=a$+".5"
tm&=&gettickcount-tm&
case manuell%: cls
print " ";a$;" "
print " ";anz%,"Stellen, ",tm&,"ms"
case manuell% :Waitinput
if anz%=0
cls:print
manuell%=0
goto "eingabe"
endif
m$=a$
goto "nochmal"
Alles anzeigen