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

prolog programming prolog programming % problem 2 (recursive arithmetic) % Implement gcd (N1, N2,

% 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!