Prolog factorial recursion

后端 未结 8 1835
無奈伤痛
無奈伤痛 2021-01-11 12:16

I\'m having trouble understanding the following factorial program

fact1(0,Result) :-
    Result is 1.
fact1(N,Result) :-
    N > 0,
    N1 is N-1,
    fac         


        
8条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-11 12:54

    factorial(1, 1).
    factorial(N, Result) :- M is N - 1,
    factorial(M, NextResult), Result is NextResult * N.
    

提交回复
热议问题