0% found this document useful (0 votes)
63 views

Prolog Assignments

The document contains 5 programming assignments in Prolog: 1) Write a program to perform basic arithmetic operations like addition, subtraction, multiplication and division. 2) Write a program to calculate the factorial of a number. 3) Write a program to calculate the area of basic shapes like circle, triangle and square. 4) Write a program to determine if a number is even or odd. 5) Write a program to find the maximum of two numbers.

Uploaded by

Shikha Arya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Prolog Assignments

The document contains 5 programming assignments in Prolog: 1) Write a program to perform basic arithmetic operations like addition, subtraction, multiplication and division. 2) Write a program to calculate the factorial of a number. 3) Write a program to calculate the area of basic shapes like circle, triangle and square. 4) Write a program to determine if a number is even or odd. 5) Write a program to find the maximum of two numbers.

Uploaded by

Shikha Arya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment 1

1.Write a program in PROLOG to perform all arithmetic operations in prolog.

sum(X,Y,Result):-

X>0, Y>0,

Result is X+Y.

sum(X,Y,Result):-

X>0, Y>0,

Result is X-Y.

sum(X,Y,Result):-

X>0, Y>0,

Result is X*Y.

sum(X,Y,Result):-

X>0, Y>0,

Result is X/Y.

2. Write a program in PROLOG to find the factorial of a number.

fact1(0,Result) :-

Result is 1.

fact1(N,Result) :-

N > 0,

N1 is N-1,

fact1(N1,Result1), Result is Result1*N.

3. Write a program in PROLOG to calculate the area of circle, triangle and square.
area_circle(R,Result):-
R>0,
Result is R*R*3.14.
area_triangle(B,H,Result):-
B>0,H>0,
Result is 0.5* H*B.

4. Write a program in PROLOG to find even or odd number.


even(X):-(X mod 2=:=0->write('even');write('odd')).

5. Write a program in PROLOG to find maximum of two number.


max(X,Y,Z):-X<Y,write(number,Y).

You might also like