Write a Prolog program to implement power (Num,Pow, Ans) : where Num is raised to the power Pow to get Ans.

6. Write a Prolog program to implement power (Num,Pow, Ans) : where Num is raised to the power Pow to get Ans.

% Write a Prolog program to implement power (Num,Pow, Ans) : where 
  Num is raised to the power Pow to get Ans.

%  below power function is not predefined you can use any name as function

power(0,P,0):- P>0.
power(X,0,1):- X>0.
power(X,P,A):- X>0,P>0,P1 is P-1,
power(X,P1,Ans),
A is Ans*X.

% Output


No comments:

Post a Comment

Featured post

Amazon Interview Process

On July 5, 1994, Jeff Bezos started the world's most "customer-centric" firm out of his garage in Bellevue, Washington. The A...