Program program have calculate m tends to n power.In the program we need to take input.predicates from user is m and n.The type of value takes as integer,not foat supports.There is some allready solution takes as
- if m=0 and n=any then m^n=0.
- If m=any and n=1 then m^n=1.
- decrease multiplication of m to n and decrease value of n.
- Then need to multiplication m with original value of n.
- That's process until n get 0.
- The program is given below:
Here we used below type of predication and clauses:
predication:power(int,int,int) and clauses go and power(m,n,ans).here ans is used for the result.We
need to display result using ans.
go
power(integer,integer,integer)
clauses
go:-
write("Enter the value of m:"),
readint(M),
write("Enter the value of n:"),
readint(N),
power(M,N,A),
write("M power N is:",A,"\n").
power(M,0,A):-
A=1.
power(0,N,A):-
A=0.
power(M,N,A):-
B=N-1,
power(M,B,S),
A=M*S.
power(integer,integer,integer)
clauses
go:-
write("Enter the value of m:"),
readint(M),
write("Enter the value of n:"),
readint(N),
power(M,N,A),
write("M power N is:",A,"\n").
power(M,0,A):-
A=1.
power(0,N,A):-
A=0.
power(M,N,A):-
B=N-1,
power(M,B,S),
A=M*S.