Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing an lisp function (Provide proof it works) Write a function in Lisp computing the greatest common divisor of two numbers. You

I need help writing an lisp function (Provide proof it works)

Write a function in Lisp computing the greatest common divisor of two numbers. You can assume that both parameters of this function are positive numbers.

Use Euclid's algorithm for this and a while loop.

Euclid's algorithm. Let n and m be the two numbers. Let dividend = n, divisor = m, and remainder be 3 local variables. Then the algorithm will perform the operations:

remainder = dividend % divisor; dividend = divisor; divisor = remainder; 

until the remainder is equal to 0 (use the predicate =). Then the value of the dividend at that point is the result of the function.

Result examples (gcdex 12 18) ; return 6 (gcdex 33 64) ; returns 1 (gcdex 100 15) ; returns 5

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

Step: 3

blur-text-image

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

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions