Write a small C++ program that defines a recursive function GCD based on the model of the Lisp function  (defun gcd (n m) "Returns the gcd of two numbers"   (let ((dividend n) (divisor m) (remainder 1))     (while (/= remainder 0)       (setq remainder (mod dividend divisor))       (setq dividend divisor)       (setq divisor remainder))     dividend)) In the main function, write a loop (while or do) that repeats the following actions: ask the user to enter two numbers, compute their GCD and output it, until the user enters 0 for one of the numbers.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
icon
Related questions
Question

Write a small C++ program that defines a recursive function GCD based on the model of the Lisp function 

(defun gcd (n m)
"Returns the gcd of two numbers"
  (let ((dividend n) (divisor m) (remainder 1))
    (while (/= remainder 0)
      (setq remainder (mod dividend divisor))
      (setq dividend divisor)
      (setq divisor remainder))
    dividend))

In the main function, write a loop (while or do) that repeats the following actions: ask the user to enter two numbers, compute their GCD and output it, until the user enters 0 for one of the numbers.

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

I can't get it working, can you post a photo of your code? Maybe I'm foamtting it wrong. I'm not familiar with C++

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Fibonacci algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning