Prolog program to implement multi (N1, N2, R) : where N1 and N2 denotes the numbers to be multiplied and R represents the result.

7. Write Prolog program to implement multi (N1, N2, R) : where N1 and N2 denotes the numbers to be multiplied and R represents the result.

% Write Prolog program to implement multi (N1, N2, R) : where N1 and N2 denotes the 
  numbers to be multiplied and R represents the result.

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

m(N,1,N).
m(N,M,A):-
T is M-1,
m(N,T,Y),
A is Y+N.

% 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...