English
Source / code snippets

russian Bauernmultiplikation for long positive Zahlenstrings

 

p.specht

Notes: for Profan-versions > 11.2 Please the parts with the Variable ´Probe!´ to remove!
Window Title "Russische Bauernmultiplikation"
' (CL) Copyleft 2012-08 by P<punkt>Specht<at>gmx.at
' No however geartete Gewähr!
Window Style 1048:Font 2:Randomize
Cls 15790320+rgb(rnd(15),rnd(15),rnd(15))
Declare R#:Struct R=Left&,Top&,Right&,Bottom&:Dim R#,R
External("user32.dll","SystemParametersInfoA",48,0,R#,0)

With R#:Window .Left&,.Top&- .Right&,.Bottom&:EndWith

    Dispose R#
    Declare md$,mr$,sum$,probe!
    Set("decimals",18)
    Nochmal:
    print "\n Multiplikand  =",:input md$
    print "\n Multiplikator =",:input mr$
    print "\n product       =",
    probe!=val(md$)*val(mr$)

    if md$>mr$:sum$=md$:md$=mr$:mr$=sum$:sum$="":endif

        sum$=""
        case val(right$(md$,1)) mod 2:sum$=mr$

        Repeat

            md$ = Halbiere(md$)
            mr$ = Verdopple(mr$)
            case val(right$(md$,1)) mod 2 : sum$ = add(sum$,mr$)

        Until val(left$(md$,2))=0

        print sum$;" "

        if probe!<10^15

            print "\n Probe (Float) = ";probe!

        else

            print "\n Probe (Float)= ";stature$("%e",probe!)

        endif

        WaitInput
        case %csrlin>35:Cls 15790320+rgb(rnd(15),rnd(15),rnd(15))
        goto "Nochmal"

        proc Verdopple

            parameters m$
            declare c$,c%,a%,r%,a$,tm&,vz%,anz%,manually%
            manually%=1
            anz%=len(m$)
            tm&=&gettickcount
            m$=trim$(m$)

            if left$(m$,1)="-"

                vz%=-1
                m$=mid$(m$,2,len(m$)-1)

            endif

            a$=""
            r%=0

            whileloop len(m$),1,-1

                c$ = mid$(m$,&loop,1)
                c%=val(c$)
                a%=2*c%+r%
                r%=0

                if a%>9

                    a%=a%-10
                    r%=1

                endif

                a$=st$(a%)+a$

            endwhile

            case r%=1:a$="1"+a$
            a$=a$+":"
            a$=translate $(a$,"0"," ")
            a$=trim$(a$)
            a$=translate $(a$," ","0")
            a$=left$(a$,len(a$)-1)
            case vz%= -1:a$="-"+a$
            return a$

        endproc

        proc Halbiere : parameters m$

            declare c$,c%,a%,r%,a$,tm&,vz%,anz%,manually%
            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$+st$(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)
            case vz%= -1:a$="-"+a$
            return a$

        endproc

        proc add : parameters a$,b$

            declare s$,la&,lb&,l&,a&,b&,c&,s&,i&,si$,carry&,lc&
            a&=0:b&=0:s$="":S&=0:c&=0:carry&=0:lc&=0'last carry
            la&=len(A $):lb&=len(B$):l&=la&

            If lb&>la&:l&=lb&:A$=Mkstr$(" ",lb&-la&)+A$

                Else :B$=Mkstr$(" ",la&-lb&)+B$:Endif

                Whileloop 0,l&-1

                    i&=l&-&Loop
                    a&=val(Mid$(A$,i&,1))
                    b&=val(Mid$(B$,i&,1))
                    c&=carry&+a&+b&
                    s&=c& mod 10
                    carry&= c& \ 10
                    lc&=carry&
                    si$=st$(s&):s$=si$+s$

                EndWhile

                s$=if(lc&,st$(lc&)," ")+s$
                s$=s$+":"
                s$=translate $(s$,"0"," ")
                s$=trim$(s$)
                s$=translate $(s$," ","0")
                s$=left$(s$,len(s$)-1)
                return s$

            ENDPROC

 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
04/25/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

604 Views

Untitledvor 0 min.
N.Art07/21/22
Ernst07/21/21
Georg Teles07/07/21
Stephan Sonneborn07/05/21
More...

Themeninformationen

this Topic has 1 subscriber:

p.specht (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie