database
frequency(integer,integer)
predicates
start
initfreq(integer)
writing
notzero(integer)
go(integer)
count(integer)
occuring_digit(integer,integer)
goal
clearwindow,
initfreq(9),
start,
writing.
clauses
initfreq(Num):-
asserta(frequency(Num,0)),
NN = Num - 1,
notzero(NN),
initfreq(NN).
initfreq(_).
notzero(Num) :-
Num <> 0.
start:-
write("\nEnter any positive number = "),
readint(Num),
go(Num).
go(Num):-
Reminder = (Num mod 10),
count(Reminder),
Temp = (Num div 10),
notzero(Temp),
go(Temp).
go(_).
count(Num):-
frequency(Num,Freq),
retract(frequency(Num,Freq)),
FF = Freq + 1,
asserta(frequency(Num,FF)).
writing:-
write("\nDigit\tFrequency\n"),
fail.
writing:-
frequency(Num,Freq),
retract(frequency(Num,Freq)),
occuring_digit(Num,Freq),
fail.
writing.
occuring_digit(Num,Freq):-
notzero(Freq),
writef("%-5\t%-9",Num,Freq),nl.
occuring_digit(_,_).