Question: 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

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!