Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I do this in prolog?

Status
Not open for further replies.

nesfrank

Programmer
Oct 5, 2009
6
US
Give a tail-recursive definition for each of the following predicates.
power(X,Y,Z): XY=Z.
gcd(X,Y,Z): The greatest common divisor of X and Y is Z.
sum(L,Sum): Sum is the sum of the elements in L.


Thank you very much and God bless your day
 
Try something, give your codes and asks questions.
 
Joel, I am trying and learning but this language sounds hard to me.... please help us as this can be used also as repository for the site. I just started to learn some programming, please please help
 
Here is one of the templates for working with lists

Code:
% when the list is empty, Current_Value and Final_Value are unified
processing_my_list([], Final_Value, Final_Value).

processing_my_list([H|T], Current_Value, Final_Value) :-
	working_with_current_element(H, Current_Value, New_Current_Value),
	processing_my_list(T, New_Current_Value,Final_Value).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top