Multiplication grands nombres

Les derniers trucs auxquels vous avez joué, les derniers ordinateurs que vous avez bidouillés.

Modérateur : Politburo

Ben
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 1549
Enregistré le : 21 août 2016 19:04

Re: Multiplication grands nombres

Message par Ben »

Effectivement, le diviseur ne l'est pas. C'est une des améliorations. Tout comme avoir des nombres négatifs ou à virgule.
Ben
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 1549
Enregistré le : 21 août 2016 19:04

Re: Multiplication grands nombres

Message par Ben »

De plus, la division ne donne que 20 chiffres derrière la virgule. Pour en voir plus, il faut changer la boucle de la ligne 585
Ben
Fonctionne à 2400 bauds
Fonctionne à 2400 bauds
Messages : 1549
Enregistré le : 21 août 2016 19:04

Re: Multiplication grands nombres

Message par Ben »

Encore des petites améliorations. Pour les exposants, mettre le nombre dans nbr1 et l'exposant dans nbr2 et "^" dans l'opérateur :-)

J'attends, évidemment, toutes vos critiques constructives :-)

Code : Tout sélectionner

10 clear:dim n$(1)*80:dim t(80)
20 input "nbr1=";n$(0):input "nbr2=";n$(1):input "oper=";o$
25 if o$="/" gosub 500:goto 98
30 if len(n$(0))>len(n$(1)) let l=len(n$(0)):goto 36
35 l=len(n$(1))
36 if l<5 let w=5-l:l=l+w:goto 6010 clear:dim n$(1)*80:dim t(80)
20 input "nbr1=";n$(0):input "nbr2=";n$(1):input "oper=";o$
25 if o$="/" gosub 500:goto 98
30 if len(n$(0))>len(n$(1)) let l=len(n$(0)):goto 36
35 l=len(n$(1))
36 if l<5 let w=5-l:l=l+w:goto 60
37 a=l-int(l/5)*5
38 if a=0 then 60
40 w=5-a:l=l+w
60 if len(n$(0))<l let n$(0)="0"+n$(0):goto 60
70 if len(n$(1))<l let n$(1)="0"+n$(1):goto 70
80 if o$="+" gosub 100:goto 90
81 if o$="-" gosub 200:goto 90
82 if o$="*" gosub 300:goto 90
83 if o$="^" gosub 650
90 if l<24 then 97
92 for i=1 to l/24+1 step 24:print mid$(n$(0),i,24):next i:goto 98
97 print n$(0)
98 end
99 rem addition
100 r=0:b=0
110 for i=l-4 to 1 step -5
120 n=val(mid$(n$(0),i,5)):m=val(mid$(n$(1),i,5))
130 a=n+m+r:r=0
140 if a<99999 then 160
150 r=int(a/100000):a=a-r*100000
160 b=b+1:t(b)=a
170 next i
180 gosub 700
190 return
199 rem soustraction
200 r=0:b=0
210 for i=l-4 to 1 step -5
220 n=val(mid$(n$(0),i,5)):m=val(mid$(n$(1),i,5))+r:r=0
230 if m>n let n=n+100000:r=1
240 a=n-m
250 b=b+1:t(b)=a
260 next i
265 gosub 700
270 return
299 rem multiplication
300 r=0:b=0:c=0
310 for i=l-4 to 1 step -5
320 m=val(mid$(n$(1),i,5))
330 for j=l-4 to 1 step -5
340 n=val(mid$(n$(0),j,5))
350 a=n*m+r:r=0
360 if a<99999 then 380
370 r=int(a/100000):a=a-r*100000
380 b=b+1:t(b)=t(b)+a
385 if t(b)>99999 let w=int(t(b)/100000):t(b)=t(b)-w*100000:t(b+1)=t(b+1)+w
390 next j
395 if r>0 let b=b+1:t(b)=t(b)+r:r=0
400 c=c+1:w=b:b=c
410 next i
415 b=w
416 gosub 700
420 return
449 rem division
500 m=val(n$(1)):r=0:l=len(n$(0)):n$(1)=""
510 for i=1 to l
520 n=val(mid$(n$(0),i,1))+r*10:a=int(n/m)
530 n$(1)=n$(1)+str$(a)
540 r=a*m:r=n-r
550 next i
560 print "quot:";n$(1):print "reste=";r
570 if r=0 then 630
580 n$(1)=n$(1)+","
585 for i=1 to 20
590 r=r*10:a=int(r/m):c=a*m:r=r-c
600 n$(1)=n$(1)+str$(a)
610 if r=0 let i=20
615 next i
620 print n$(1)
630 return
649 rem exposant
650 d=val(n$(1)):n$(1)=n$(0)
655 if d=0 let n$(0)="00001":goto 690
660 if d=1 then 690
670 d=d-1:gosub 300:l=len(n$(0))
674 if l=len(n$(1)) then 680
675 for i=len(n$(1)) to l-1:n$(1)="0"+n$(1):next i
680 goto 660
690 return
700 if t(b)=0 then let b=b-1:goto 700
710 n$(0)=""
730 for i=b to 1 step -1
740 w$=str$(t(i)):l=len(w$)
750 if l=5 then 770
760 for j=1 to 5-l:w$="0"+w$:next j
770 n$(0)=n$(0)+w$
780 next i
790 return
37 a=l-int(l/5)*5
38 if a=0 then 60
40 w=5-a:l=l+w
60 if len(n$(0))<l let n$(0)="0"+n$(0):goto 60
70 if len(n$(1))<l let n$(1)="0"+n$(1):goto 70
80 if o$="+" gosub 100:goto 90
81 if o$="-" gosub 200:goto 90
82 if o$="*" gosub 300:goto 90
83 if o$="^" gosub 650
90 if l<24 then 97
92 for i=1 to l/24+1 step 24:print mid$(n$(0),i,24):next i:goto 98
97 print n$(0)
98 end
99 rem addition
100 r=0:b=0
110 for i=l-4 to 1 step -5
120 n=val(mid$(n$(0),i,5)):m=val(mid$(n$(1),i,5))
130 a=n+m+r:r=0
140 if a<99999 then 160
150 r=int(a/100000):a=a-r*100000
160 b=b+1:t(b)=a
170 next i
180 gosub 700
190 return
199 rem soustraction
200 r=0:b=0
210 for i=l-4 to 1 step -5
220 n=val(mid$(n$(0),i,5)):m=val(mid$(n$(1),i,5))+r:r=0
230 if m>n let n=n+100000:r=1
240 a=n-m
250 b=b+1:t(b)=a
260 next i
265 gosub 700
270 return
299 rem multiplication
300 r=0:b=0:c=0
310 for i=l-4 to 1 step -5
320 m=val(mid$(n$(1),i,5))
330 for j=l-4 to 1 step -5
340 n=val(mid$(n$(0),j,5))
350 a=n*m+r:r=0
360 if a<99999 then 380
370 r=int(a/100000):a=a-r*100000
380 b=b+1:t(b)=t(b)+a
385 if t(b)>99999 let w=int(t(b)/100000):t(b)=t(b)-w*100000:t(b+1)=t(b+1)+w
390 next j
395 if r>0 let b=b+1:t(b)=t(b)+r:r=0
400 c=c+1:w=b:b=c
410 next i
415 b=w
416 gosub 700
420 return
449 rem division
500 m=val(n$(1)):r=0:l=len(n$(0)):n$(1)=""
510 for i=1 to l
520 n=val(mid$(n$(0),i,1))+r*10:a=int(n/m)
530 n$(1)=n$(1)+str$(a)
540 r=a*m:r=n-r
550 next i
560 print "quot:";n$(1):print "reste=";r
570 if r=0 then 630
580 n$(1)=n$(1)+","
585 for i=1 to 20
590 r=r*10:a=int(r/m):c=a*m:r=r-c
600 n$(1)=n$(1)+str$(a)
610 if r=0 let i=20
615 next i
620 print n$(1)
630 return
649 rem exposant
650 d=val(n$(1)):n$(1)=n$(0)
655 if d=0 let n$(0)="00001":goto 690
660 if d=1 then 690
670 d=d-1:gosub 300:l=len(n$(0))
674 if l=len(n$(1)) then 680
675 for i=len(n$(1)) to l-1:n$(1)="0"+n$(1):next i
680 goto 660
690 return
700 if t(b)=0 then let b=b-1:goto 700
710 n$(0)=""
730 for i=b to 1 step -1
740 w$=str$(t(i)):l=len(w$)
750 if l=5 then 770
760 for j=1 to 5-l:w$="0"+w$:next j
770 n$(0)=n$(0)+w$
780 next i
790 return
Répondre

Retourner vers « A quoi t'as joué hier ? »