Consider the Prolog gcd program in Figure 1.2. Does this program work backward as well as forward?

Question:

Consider the Prolog gcd program in Figure 1.2. Does this program work “backward” as well as forward? (Given integers d and n, can you use it to generate a sequence of integers m such that gcd(n, m) = d?) Explain your answer.

Figure 1.2:

int gcd(int a, int b) { // C while (a != b) { if (a > b) a = a - b; else b = b - a; return a; (* OCaml *) let rec gcd a b = if a = b then a else if a > b

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: