如何在prolog中对整数列表中的偶数进行求和

时间:2016-04-05 12:49:28

标签: prolog

evennum(N) :- 0 is N mod 2.
nonevennum(N) :- 1 is N mod 2.
sumsq_even([], 0).
sumsq_even([N | TailN], Sum) :-
  evennum(N), sumsq_even(TailN, S), Sum is S + N * N.
sumsq_even([N | TailN], Sum) :-
  sumsq_evennum(TailN, Sum),sumsq_even(TailN, S),Sum is S.

0 个答案:

没有答案