I am new in prolog, when user input list of number it will only sum the composite number.
composite Number: 4,6,8 ... etc
. So far I done sum of list in prolog
.But really got problem how I can find composite number in prolog?
Can find sum by this
list_sum( [] , 0 ) .
list_sum( [Head|Tail] , TotalSum ) :-
list_sum(Tail,Sum1) ,
Total = Head+Sum1 .
You need to add a predicate
is_composite/1
that succeed if its argument is a composite number. This is how I'd do it :A composite number is:
And a prime number, of course, is its converse,
So one way of defining a composite number would be to check for primeness, something like:
There's lots out there on how to determine primeness. You should be able to figure it out.