Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

prolog programming % problem 2 (recursive arithmetic) % Implement gcd (N1, N2, N3) such that N3 is the greatest common & divisor of Ni and

prolog programming image text in transcribed
% problem 2 (recursive arithmetic) % Implement gcd (N1, N2, N3) such that N3 is the greatest common & divisor of Ni and N2. (Assume ni, N2 are positive ints or 0.) % Implement using recursion. Mathematical definiton of ged: & gcd(x, y) = x if y=0 & gcd(x, y) = gedly, remainder(x,y)) if y > 0. % Prolog note: to compute remainder use the built-in & mod predicate. Here's an example of using it: % ? - Z is 5 mod 2. % Z=1. % Test cases: % ? - gcd (5, 0, 5). % true. % ? - gcd (5, 7, 1). % true. % ? - gcd (5, 7, 2). & false. % ? - gcd (21, 18, 3). % true. & Note: type '.' after first answer to N in each of these: % ? - gcd (5, 0, N). % N = 5. $ ? - gcd (5, 7, N). % N = = 1. % ?- gcd (21, 18, N). % N = 3. % Write you solution here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago