yuriythebest2
Programmer
hi! I need to find the sum of all positive numbers up to N, with the step of D, for instance id D=3 and N=11 then 11+8+5+2=26. Currently my way is like so:
sum(N, D, Res) :- D<N, N1 is N - D, sum(N1, D, Res1), Res is Res1+N1.
however this yields the answer 17 which is incorrect please help!
sum(N, D, Res) :- D<N, N1 is N - D, sum(N1, D, Res1), Res is Res1+N1.
however this yields the answer 17 which is incorrect please help!