Implementazioni di algoritmi/Algoritmo di Euclide: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m Update syntaxhighlight tags - remove use of deprecated <source> tags
 
Riga 7:
=== [[C]]/[[C++]]/[[Java]] ===
; versione ricorsiva
<sourcesyntaxhighlight lang="c">
int mcd(int a, int b) {
if (b == 0)
Riga 14:
return mcd(b, a % b);
}
</syntaxhighlight>
</source>
 
; versione non ricorsiva
<sourcesyntaxhighlight lang="c">
int mcd(int a, int b) {
int t;
Riga 27:
return a;
}
</syntaxhighlight>
</source>
 
=== [[Python]] ===
; versione ricorsiva
<sourcesyntaxhighlight lang="python">
def mcd(a,b):
if b==0:
Riga 37:
else:
return mcd(b,(a%b))
</syntaxhighlight>
</source>
 
; versione non ricorsiva
<sourcesyntaxhighlight lang="python">
def mcd(a, b):
while b:
a, b = b, a%b
return a
</syntaxhighlight>
</source>
 
=== [[MATLAB]]/Octave ===
; versione ricorsiva
<sourcesyntaxhighlight lang="MATLAB">
function val = mcd(a, b):
if b == 0
Riga 56:
val = mcd(b, rem(a,b))
end
</syntaxhighlight>
</source>
 
; versione non ricorsiva
<sourcesyntaxhighlight lang="MATLAB">
function val = mcd(a, b):
if b == 0
Riga 68:
b = rem(temp,b);
end
</syntaxhighlight>
</source>
 
=== [[Visual basic.net|Visual Basic .NET]] ===
; versione non ricorsiva
<sourcesyntaxhighlight lang="vb">
Function MCD(ByVal a As Integer, ByVal b As Integer) As Integer
Dim m As Decimal
Riga 82:
Return a
End Function
</syntaxhighlight>
</source>
 
[[Categoria:Implementazioni di algoritmi|Algoritmo di Euclide]]