21.12.2012 Views

1.5 Algoritmo de Euclides con menor resto. - TEC-Digital

1.5 Algoritmo de Euclides con menor resto. - TEC-Digital

1.5 Algoritmo de Euclides con menor resto. - TEC-Digital

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

8 Revista digital Matemática, Educación e Internet (www.cidse.itcr.ac.cr/revistamate/). Vol 10, No 2. , Marzo 2010.<br />

<strong>Algoritmo</strong> 1.1: Máximo común divisor: <strong>Algoritmo</strong><br />

<strong>de</strong> Eucli<strong>de</strong>s<br />

Entrada: a, b ∈ Z, b �= 0.<br />

Resultado: mcd (a, b)<br />

if a = 0 then<br />

return mcd (a, b) = b<br />

c = a, d = b ;<br />

while d �= 0 do<br />

r =crem(c, d);<br />

c = d;<br />

d = r;<br />

return mcd (a, b) = c;<br />

Implementación. La función crem necesita la función cquo.<br />

Function cquo(a,b) As Long<br />

Dim q As Long<br />

If b=0 then<br />

msgbox "Error, b=0"<br />

Exit Function<br />

End If<br />

q = Int(a/b)<br />

If b

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!