Welcome

User: Pass:   register


Determines the Greatest Common Divider (GCD) of two given numbers. If you don't know what a GCD is, you don't need the code :)

Usage: /gcd N1 N2 where both N1 and N2 are integers

alias gcd {
  if (!$2) || ($3) { echo -a error: wrong number of arguments. Provide only 2. | halt }
  if ($1 == $2) { echo -a error: two given numbers cannot be the same. | halt }
  if ($int($1) != $1) || ($int($2) != $2) { echo -a error: you need to provide two integers. | halt }
  if ($1 > $2) { set %1 $1 | set %2 $2 }
  else { set %1 $2 | set %2 $1 }
  :start
  if (%1 == %2) { echo -a error: both integers are the same | halt }
  set %div $calc(%1 % %2)
  if (%div == 0) { echo -a GCD found: %2 | halt }
  else {
    set %1 %2
    set %2 %div
  }
  goto start
}






© 1996-2010 hdesk.org and dalnethelpdesk.com