J' aimerais tout simplement une amélioration de ce programme "PGCD ÉTENDUE" qui appartient à Laurae pack bac .
Celui ci est excellent mais se trompe avec par exemple avec le PGCD(109,226) il me donne une réponse fausse de plus c 'est le seul programme qui me donne les détails . Un must !!!
- Code: Select all
Define pgcd(c0,d0)=
Prgm
:Local c0,d0,x
:c:=c0
:d:=d0
:a[1]:=0
:a[2]:=0
:b[1]:=0
:b[2]:=0
:q[1]:=0
:q[2]:=0
:k[1]:=1
:k[2]:=2
:r[1]:=c
:r[2]:=d
:u[1]:=1
:u[2]:=0
:v[1]:=0
:v[2]:=1
:x:=3
:a[x]:=c
:b[x]:=d
:q[x]:=floor(((a[x])/(b[x])))
:r[x]:=a[x]-b[x]*q[x]
:k[x]:=3
:u[x]:=q[x]*u[x-1]+u[x-2]
:v[x]:=−q[x]*v[x-1]+v[x-2]
:Disp "Étape 1 : ",a[x]," = ",b[x],"*",q[x],"+",r[x]
:Disp a[x],"*",u[x],"+",b[x],"*",v[x]," = ",r[x]
:x:=4
:a[x]:=b[x-1]
:b[x]:=r[x-1]
:q[x]:=floor(((a[x])/(b[x])))
:r[x]:=a[x]-b[x]*q[x]
:k[x]:=x
:u[x]:=−q[x]*u[x-1]+u[x-2]
:v[x]:=−q[x]*v[x-1]+v[x-2]
:Disp "Étape 2 : ",a[x]," = ",b[x],"*",q[x],"+",r[x]
:Disp a[x],"*",u[x],"+",b[x],"*",v[x]," = ",r[x]
:While r[x]>1
: x:=x+1
: a[x]:=b[x-1]
: b[x]:=r[x-1]
: q[x]:=floor(((a[x])/(b[x])))
: r[x]:=a[x]-b[x]*q[x]
: k[x]:=x
: u[x]:=−q[x]*u[x-1]+u[x-2]
: v[x]:=−q[x]*v[x-1]+v[x-2]
: Disp "Étape ",x-2," : ",a[x]," = ",b[x],"*",q[x],"+",r[x]
: If r[x]>1 Then
: Disp a[x],"*",u[x],"+",b[x],"*",v[x]," = ",r[x]
: Else
: Disp "Fin de l'algorithme d'Euclide"
: u[x]:=0
: v[x]:=0
: EndIf
:EndWhile
:Disp " "
:Disp "pgcd(",c,",",d,") = ",b[x]
:x:=x-1
:Disp "bezout(",c,",",d,") : ",c,"*",u[x],"+",d,"*",v[x]," = ",r[x]
:x:=x+1
:EndPrgm
PS: Je ne suis pas développeurs