Funcion en prolog AYUDA!!!!!
Publicado por Nuria (2 intervenciones) el 18/11/2008 14:19:15
Hola, quisiera saber como puede prolog devolver un valor... te pego aqui el ejercicio..
% P32 (**) Determine the greatest common divisor of two positive integers.
% gcd(X,Y,G) :- G is the greatest common divisor of X and Y
% (integer, integer, integer) (+,+,?)
gcd(X,0,X) :- X > 0.
gcd(X,Y,G) :- Y > 0, Z is X mod Y, gcd(Y,Z,G).
% Declare gcd as an arithmetic function; so you can use it
% like this: ?- G is gcd(36,63).
%%:- arithmetic_function(gcd/2).
Pliiissss!!! no sé como implementar la función gcd(X,Y). ¿Cómo se puede devolver el valor en prolog? ya no se que más buscar!!! SOS
Muchas gracias, Saludos.
% P32 (**) Determine the greatest common divisor of two positive integers.
% gcd(X,Y,G) :- G is the greatest common divisor of X and Y
% (integer, integer, integer) (+,+,?)
gcd(X,0,X) :- X > 0.
gcd(X,Y,G) :- Y > 0, Z is X mod Y, gcd(Y,Z,G).
% Declare gcd as an arithmetic function; so you can use it
% like this: ?- G is gcd(36,63).
%%:- arithmetic_function(gcd/2).
Pliiissss!!! no sé como implementar la función gcd(X,Y). ¿Cómo se puede devolver el valor en prolog? ya no se que más buscar!!! SOS
Muchas gracias, Saludos.
Valora esta pregunta


0