--AUTOR: Jose Luis VILLARIG GARCIA (V2975813) 472542@cepsz.unizar.es --PROYECTO: Ejercicio --FICHERO: mcd.adb --FECHA: Octubre-Noviembre 1999 --Modidicado por: --Fecha modificacion: --Descripcion: Este programa halla el mcd y el mcm de dos numeros --Se basa en las formulas: --a>b, mcd(a,b)=mcd(b,r), donde r es a mod b --mcm(a,b)=a*b/mcd(a,b) with text_io, Ada.integer_text_io; use text_io, Ada.integer_text_io; procedure mcd is procedure intercambiar (a,b : in out integer) is guardaB : integer; begin guardaB := b; b := a; a := guardaB; end intercambiar; -- declaracion de constantes y variables a, b, resto, mcd, mcm, guardaA, guardaB: integer; begin resto := 1; put ("Introduce dos numeros :"); get (a); get (b); if a < b then -- si a < b las formulas son ciertas, pero no operativas. intercambiar(a,b); end if; guardaA := a; guardaB := b; while resto /= 0 loop resto := a mod b; a := b; b := resto; end loop; mcd := a; -- porque el valor de b ha pasado a put ("el mcd es: "); put (mcd,0); new_line; put ("el mcm es: "); mcm := (guardaA/mcd)*guardaB; -- hacerlo así produce menos desbordamientos put (mcm,0); end mcd;