Logo 
Search:

Artificial Intelligence Forum

Ask Question   UnAnswered
Home » Forum » Artificial Intelligence       RSS Feeds

Simple prolog program to be solved :)

  Asked By: Hasan    Date: May 03    Category: Artificial Intelligence    Views: 1518
  

Hi,
I am new in prolog programming and I have a simple program to be solved.

A Prolog program that will take two integers and the operation (sum, subtract, multiplication, division) as input and return the operation’s result of that integers as output

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Abhishek Singh     Answered On: May 14

if you know c language then you can do it.
best of luck.






 
Answer #2    Answered By: Robert Smith     Answered On: Jul 23

%for all you late visitors to this post (like myself):-)

blah(multiply,A,B,Ans) :- Ans is A*B.
blah(divide,A,B,Ans) :- Ans is A/B.
blah(add,A,B,Ans) :- Ans is A+B.
blah(subtract,A,B,Ans) :- Ans is A-B.

?- blah(add,3,4,X).
X = 7.

?- blah(Y,3,4,X).
Y = multiply,
X = 12 ;
Y = divide,
X = 0.75 ;
Y = add,
X = 7 ;
Y = subtract,
X = -1.

?-

 
Didn't find what you were looking for? Find more on Simple prolog program to be solved :) Or get search suggestion and latest updates.




Tagged: