0 Replies - 185 Views - Last Post: 25 October 2007 - 05:41 AM

#1 spullen   User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 356
  • Joined: 22-March 07

[Scheme] Greatest Common Divisor

Posted 25 October 2007 - 05:41 AM

Description: Input two numbers a and b to find the GCD. Example: (gcd 77 64) ; => returns 1 (gcd 91 77) ; => return 7This has probably been done to death, but I decided to make a method to compute the gcd in scheme (which has come in handy for the discrete math course I am taking :) ). This is also an example of a recursive algorithm in scheme.
(define (gcd a b)
  (if (= b 0) a
      (gcd b (modulo a b))))

Is This A Good Question/Topic? 0
  • +

Page 1 of 1