0% found this document useful (0 votes)
21 views4 pages

21 To 30 Prolog Program

The document contains examples of Prolog programs for finding the maximum and minimum number in a list, checking if a list length is even or odd, summing two numbers, and finding the length of a given list.

Uploaded by

CHANDRA BHUSHAN
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

21 To 30 Prolog Program

The document contains examples of Prolog programs for finding the maximum and minimum number in a list, checking if a list length is even or odd, summing two numbers, and finding the length of a given list.

Uploaded by

CHANDRA BHUSHAN
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

MANTHAN MODI

Q:1 Find Maximum number in prolog. max:-write('Enter first number'),nl, read(Num1),nl, write('Enter second number'), nl,read(Num2),nl, write('Enter third number'),nl,read(Num3), find_max(Num1,Num2,Num3).

find_max(Num1,Num2,Num3):-(Num1>Num2,Num1>Num3->nl,write(Num1), write(' is the biggest'),!); (Num2>Num3->nl,write(Num2),write(' is the biggest'),!);nl,write(Num3), write(' is the biggest'),!. Output: | ?- max. Enter first number 50.

Enter second number 35.

Enter third number 75.

75 is the biggest

Q:2find out minimum number in prolog. minl([A], A). minl([A|B], C) :minl(B, D),

C is min(A, D).

(16 ms) yes OUTPUT:| ?- minl([7,8,45,2,53],X).

X=2? Q:3 Code for Prolog program to find whether the length of a list is even or odd in Prolog domains x = integer l = integer* predicates length(l,x) evenlength(l) oddlength(l) clauses length([],0). length([X|List],Length) :length(List,Length1), Length = Length1 + 1. evenlength(List) :length(List,Length), Length mod 2 = 0. oddlength(List) :length(List,Length), Length mod 2 <> 0. Output : For evenlength : Goal: evenlength([1,2,3,4]) Yes Goal: evenlength([1,2,3,4,5]) No For oddlength :

Goal: oddlength([1,2,3,4,5]) Yes Goal: oddlength([1,2,3,4]) No Q:4 Sum of two number. start:- sum,nl.

sum:- write('X= '),read(X), write('Y= '),read(Y), S is X+Y, write('Sum is '),write(S). output sum:- X=55. Y=20. Sum is 75 Q:5 program to find the length of a given list in prolog. domains list=symbol* predicates len(list) findlen(list,integer) clauses len(X):findlen(X,Count), write("\nLength Of List : "), write(Count). findlen([],X):X=0.

findlen([X|Tail],Count):findlen(Tail,Prev), Count = Prev + 1. OUT PUT ======= Goal: len([a,b,c,d,e]) Length Of List : 5 Yes

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy