20_09

Write a Prolog program to implement two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length respectively.

 Source Code :

 

evenlength:-

 write('true --> even').

oddlength:-

 write('true --> odd').

 

oddeven([_H|T]):-

 length(T,L),

 L>=0 ->

 (

  L1 is L+1,

  L2 is mod(L1,2),

  L2=:=0 ->

   evenlength

  ;

   oddlength

 ).

 

Output :

Prolog program to implement two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length respectively


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...