I need to find the factors of a given number , e.g :
?- divisors2(40,R). R = [40,20,10,8,5,4,2,1].
The code :
% get all t
You have a bug here
divisors1([H|T],S,X):- divisors1(T,W,X), Z is X mod H, Z==0,S=[H|W]. <=== here
If Z is Zero then S = [H|W] else S = W.