Home      Affiliated Colleges      Course content      First Sem     Second Sem     Third Sem     Fourth Sem     Fifth Sem     Sixth Sem     Seventh Sem     Eighth Sem     Lab report 4th sem     Contact    

Friday, February 5, 2010

Introduction to Cognitive Science-Program to find GCD



domains

num,result=integer

predicates
lcm(num,num)
lcm(num,num,result)
gcd(num,num)
gcd(num,num,result)
input()
clauses
input():-
readint(X1),
readint(X2),i
write("gcd="),gcd(X1,X2,Y),write(Y).


lcm(X1,X2):-
lcm(X1,X2,Y),write(Y),nl.
lcm(X1,X2,Y):-
gcd(X1,X2,Y1),Y=X1*X2/Y1.
gcd(X1,X2):-
gcd(X1,X2,Y),write(Y),nl.

gcd(X1,0,Y):-
Y=X1.

gcd(X1,X2,Y):-
X1=X2,Y=X2.

gcd(X1,X2,Y):-
X1<X2,gcd(X2,X1,Y).

gcd(X1,X2,Y):-
X3=X1 mod X2, gcd(X2,X3,Y).

goal
input().

No comments:

Post a Comment

^ Scroll to Top Related Posts with Thumbnails ^ Go to Top