{"id":3796,"date":"2024-09-07T18:22:35","date_gmt":"2024-09-07T18:22:35","guid":{"rendered":"https:\/\/workhouse.sweetdishy.com\/?p=3796"},"modified":"2024-09-07T18:22:36","modified_gmt":"2024-09-07T18:22:36","slug":"arithmetic-operators-in-prolog","status":"publish","type":"post","link":"https:\/\/workhouse.sweetdishy.com\/index.php\/2024\/09\/07\/arithmetic-operators-in-prolog\/","title":{"rendered":"Arithmetic Operators in Prolog"},"content":{"rendered":"\n<p id=\"Arti00011813\">Arithmetic operators are used to perform arithmetic operations. Some popularly used arithmetic operators are given in Table. To implement these operators, create a new file and save it as ao.pl. Write the following code in it.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"Arti00011814\">calc :- X is 10 + 20, write(\u201810 + 20 is \u2018),write(X),nl,<\/p>\n\n\n\n<p id=\"Arti00011815\">Y is 30 &#8211; 15, write(\u201830 &#8211; 15 is \u2018),write(Y),nl,<\/p>\n\n\n\n<p id=\"Arti00011816\">Z is 10&nbsp;<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/star.png\" alt=\"images\" width=\"7\" height=\"7\">&nbsp;5, write(\u201810&nbsp;<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/star.png\" alt=\"images\" width=\"7\" height=\"7\">&nbsp;5 is \u2018),write(Z),nl,<\/p>\n\n\n\n<p id=\"Arti00011819\">A is 200 \/ 40, write(\u2018200 \/ 40 is \u2018),write(A),nl,<\/p>\n\n\n\n<p id=\"Arti00011820\">B is 250 \/\/ 17, write(\u2018250 \/\/ 17 is \u2018),write(B),nl,<\/p>\n\n\n\n<p id=\"Arti00011821\">C is 50&nbsp;<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/star.png\" alt=\"images\" width=\"7\" height=\"7\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/star.png\" alt=\"images\" width=\"7\" height=\"7\">&nbsp;2, write(\u201850&nbsp;<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/star.png\" alt=\"images\" width=\"7\" height=\"7\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/star.png\" alt=\"images\" width=\"7\" height=\"7\">&nbsp;2 is \u2018),write(C),nl,<\/p>\n\n\n\n<p id=\"Arti00011826\">D is 220 mod 40, write(\u2018220 mod 40 is \u2018),write(D),nl.<\/p>\n<\/blockquote>\n\n\n\n<p id=\"Arti00011827\">Now, run this code in the console as shown below. Note that nl means new line.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p574-2.png\" alt=\"images\"\/><\/figure>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p574-3.png\" alt=\"images\" width=\"483\" height=\"273\"><\/p>\n\n\n\n<p><em>Credit<\/em>: Copyright (C) 1999-2021 Daniel Diaz<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Arti00011833\"><a><\/a><strong>Loops<\/strong><\/h4>\n\n\n\n<p id=\"Arti00011834\">Loop statements are used to execute one or more instructions multiple times. A set of instructions is executed in Prolog multiple times using recursive predicate logic. Unlike, C, C++, Java, there are no direct loops in Prolog. To simulate loop in Prolog, create a file count10.pl, write the instructions given below and execute it as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p575-1.png\" alt=\"images\"\/><\/figure>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p575-2.png\" alt=\"images\" width=\"525\" height=\"261\"><\/p>\n\n\n\n<p><em>Credit<\/em>: Copyright (C) 1999-2021 Daniel Diaz<\/p>\n\n\n\n<p id=\"Arti00011840\">&nbsp;<\/p>\n\n\n\n<p id=\"Arti00011841\">Let us write another program to count down from 10 to 0. Create a new file, write the instructions given below and save it as count_down_10.pl.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p575-3.png\" alt=\"images\"\/><\/figure>\n\n\n\n<p id=\"Arti00011844\">Execute the file as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p575-4.png\" alt=\"images\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Arithmetic operators are used to perform arithmetic operations. Some popularly used arithmetic operators are given in Table. To implement these operators, create a new file and save it as ao.pl. Write the following code in it. calc :- X is 10 + 20, write(\u201810 + 20 is \u2018),write(X),nl, Y is 30 &#8211; 15, write(\u201830 &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3341,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[464],"tags":[],"class_list":["post-3796","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-language-prolog"],"jetpack_featured_media_url":"https:\/\/workhouse.sweetdishy.com\/wp-content\/uploads\/2024\/08\/programming.png","_links":{"self":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts\/3796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/comments?post=3796"}],"version-history":[{"count":1,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts\/3796\/revisions"}],"predecessor-version":[{"id":3797,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts\/3796\/revisions\/3797"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/media\/3341"}],"wp:attachment":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/media?parent=3796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/categories?post=3796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/tags?post=3796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}