Prolog program to check whether a given number is Armstrong or not. - Artificial intelligence
- program to check whether a given number is Armstrong or not.
Program:
armst(X) :-
N is X,
R is X mod 10,
S is 0,
arm(N,R,S,X).
arm(N,R,S,X):-
N > 0,
S1 is S+R*R*R,
N1 is N div 10,
R1 is N mod 10,
arm(N1,R1,S1,X).
arm(N,_,S,X):-
N = 0,
S\=X,
write("Armstrong").
arm(N,_,S,X):-
N = 0,
S\=X,
write("Not Armstrong").
Output:
?- armst(1634).
Armstrong
true
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment