Skip to main content

how to implement adding of numbers in PROLOG

write a knowledge base add.pl

with the following rules:
// for two variables 

sum(X,Y):-
    S is X+Y,
   write('sum of '),write(X),write('and '),write(Y),write('is ='),write(S).

add:-
    write_ln('Enter the first number:-'),
    read(First),
    write_ln('Enter second number:-'),
    read(Second),
    S is First+Second,
     write('sum of '),write(First),write('and '),write(Second),write('is ='),write(S).




now we can close this windows and in the main WINDOW

either type  ['add.pl'].



or consult the add.pl file.


now you can call this funcation via two ways :-


?- sum(5,44).
it will give output as 
sum of 5 and 44 is 49

or you can call via 
add.
Enter the first number .
:| 45.
Enter the second Number .
:| 45.

sum of 45 and 45 is equal to 90.



note i have used sum:- instead of add:- so i have to call it via sum.

Comments

Popular posts from this blog

13 websites to register your free domain

Register your Free Domain Now!! 1)  .tk Dot TK is a FREE domain registry for websites on the Internet. It has exactly the same power as other domain extensions, but it’s free! Because it’s free, millions of others have been using .TK domains since 2001 – which makes .TK powerful and very recognizable.  Your website will be like www.yourdomainname.tk . It is free for 1 year. It’s a ccTLD domain whixh having the abbreviation  Tokelau. To create a .tk domain, Visit   www.dot.tk 2) co.cc Co.cc is completely free domain which is mostly used by blogspot bloggers because of it’s easy to use DNS system. Creating a co.cc for blogger is simple ( for instructions- “click here”). Your website will be like www.yourdomainname.co.cc . To create a .co.cc domain, visit www.co.cc 3)   co.nr co.nr is too like co.cc. Your website will be like  www.yourdomainname.co.nr . You can add it for blogger also.. To create a .co.cc domain, vi...

How to Put Google Adsense Below Post Title in Blogger?

Adsense is used by majority of expert bloggers for their website monetization because it is a cookie based contextual advertising system that shows targeted ads relevant to the content and reader. As bloggers are paid on per click basis, they try various ad placements on the blog to  increase the revenue  and get maximum clicks on the ad units. Well, on some blogs, you might have seen Adsense ad units placed below the post title. Do you know why? It is because the area just below the post title gets the most exposure and is the best place to put AdSense ad units to increase  Click Through Rate (CTR). Even though ads below post title work like a charm but this doesn’t mean that it will work for you as well. If you want to find out the best AdSense ads placement for your blog, try experimenting by placing ads at various locations such as header, sidebar, footer, etc. You can try other  blog monetization methods  as well to effectively monetize y...

what is LOREM ipsum and why do designers use it

What is Lorem Ipsum? Lorem Ipsum  is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now...

Binary Search Tree in Java implementation (reference based, dynamic memory)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 import java.util.Scanner ; class BST { static BST . Node root = null ; public void insert ( int num ) { if ( root == null ) { root = new BST . Node ( num ); } else { // root node is not empty BST . Node temp = root ; while ( temp != null ) { if ( num <= temp . getVal ()) { if ( temp . getLeft () != null ) temp = temp . getLeft (); ...

What Are Search Engine Spiders?

A spider, also known as a robot or a crawler, is actually just a program that follows, or "crawls", links throughout the Internet, grabbing content from sites and adding it to search engine indexes. Spiders only can follow links from one page to another and from one site to another. That is the primary reason why links to your site (inbound links) are so important. Links to your website from other websites will give the search engine spiders more "food" to chew on. The more times they find links to your site, the more times they will stop by and visit. Google especially relies on its spiders to create their vast index of listings. Spiders find Web pages by following links from other Web pages, but you can also submit your Web pages directly to a search engine or directory and request a visit by their spider. In fact, it's a good idea to manually submit your site to a human-edited directory such as Yahoo, and usually spiders from other search e...

Tips to Enable or Disable Toast Notifications on Windows 8

Windows 8 is among the most incredible and interesting kind of Windows version from Microsoft. It has visually eye catching design, which is found in modern user interface that is meant for redesigning a number of operating systems, worked out for users. If you have used or seen someone using Windows 8 you could have noticed the toast notifications in this modern version of windows, which simply appears the moment you install or uninstall any application. There are many users who are well versed with the bubble notifications, which were found in the earlier versions of Windows seen via the taskbar. The new application platform in Windows 8 comes with an integrated notification system for installing or uninstalling a number of modern applications. The Windows 8 style application can employ a number of notifications types including the traditional toast notifications, live titles and lock screen. These can be managed by either disabling or enabling the notification of your applicatio...

DOWNLOAD ADVANCED INSTALLER

DOWNLOAD FEATURES JAVA LICENSING PURCHASE SUPPORT FORUMS Caphyon Advanced Installer Advanced Installer The power of Windows Installer made easy Buy Download .MSI installs in Minutes Advanced Installers deploy products on millions of computers worldwide Powerful and easy to use  Windows Installer  authoring tool. Install, update and configure your products  safely, securely  and reliably . Freeware Windows Installer Free Installer Trial With Advanced Installer, packaging and deploying SourceTree is now just a simple part of our development process. We can focus our efforts on building new features in SourceTree and improving existing ones so that SourceTree becomes the best Windows interface to Git source repositories. Steve Streeting , Lead developer of SourceTree at  Atlassian Full story Windows Installer Software Windows Installer Software Windows Installer Software Windows Installer Software Wind...

Java API call Example using GSON, org.json.json and Jackson [ Simple Get Call] and parsing result as JSON

import com.fasterxml.jackson.databind.JsonNode ; import com.fasterxml.jackson.databind.ObjectMapper ; import com.google.gson.* ; import org.json.JSONArray ; import org.json.JSONObject ; import java.io.* ; import java.net.HttpURLConnection ; import java.net.URL ; public class APICALL { public static void main (String[] args) throws IOException { // String url="https://mocki.io/v1/19a50724-c2e5-46a1-b457-543462cdfde2"; String url= "https://jsonplaceholder.typicode.com/users" ; String line ; StringBuilder resp= new StringBuilder() ; System. out .println(url) ; HttpURLConnection con= (HttpURLConnection) new URL(url).openConnection() ; con.setRequestMethod( "GET" ) ; con.setRequestProperty( "Accept" , "application/json" ) ; System. out .println(con.getResponseMessage()) ; System. out .println(con.getContentType()) ; InputStream inputStream=con.getInput...

[ FREE ][ more than 15 gb for free ] Offcloud vs Bitport vs Seedr :which is best among three to direct download from torrent to cloud storages like google drive ,one drive ,dropbox etc.

Offcloud : [RECOMMENDED BY ME] [AS OF 17-july-2017] Offcloud is a little different from the rest of the providers we’ve looked at, as it isn’t focused on downloading torrents. The company markets itself as “a simple, elegant and intuitive  SaaS  to retrieve any data from the cloud.” We were surprised at the amount of different sources Offcloud supports for downloading, and it even has a ticket box that allows users to suggest new sites to support.  pros: best part you can direct download to your cloud storage like google drive , mega.NZ,one drive ,Dropbox,etc.. Cons: only 3 links permitted to download over free account ..that limit is per months .. you can buy a premium account to bypass this .............. else you can also use a fake email generator and add a remote account to cloud download bypasssing above limit.. Note that Off-cloud doesn’t intend to act as a “seedbox,” which is a server used to boost a user’s ration on private trackers by perpetua...

C++ Program to implement Exception Handling by using TRY CATCH

Write a Boolean function that returns TRUE/FALSE if the unsigned int argument passed to it is a Leap Year or Non-Leap Year. The function must throw an “Out Of Range” exception if its argument does not lie between 0 and 2100. #include #include   enum boolean{false, true} bool;   class Cyear{     private:         int dd, mm, yy;     public:         void getDate();         int isLeap();         void putDate();     };   void Cyear :: getDate(){     cout<<"\n Enter Date (dd mm yyyy): ";     cin>>dd>>mm>>yy;     try{         if( (yy < 0) || (yy > 2100) )             throw "Out of Range";         }     catch(char *errmsg){   ...