Answers for "recursion greatest common divisor"

1

greatest common divisor recursion

/* Function using "Euclidian Algorithm" to recursively find the 
greatest common divisor/factor (GCD/GCF) of 2 positive numbers*/
const gcf = function (small, large) {
    let r = large % small;
    if (r == 0)
        return small;
    else
        return gcf(r, small);
}
Posted by: Guest on August-12-2021
0

Greatest common divisor iterative

#include<stdio.h>

int gcd_iter(int u, int v) {
  if (u < 0) u = -u;
  if (v < 0) v = -v;
  if (v) while ((u %= v) && (v %= u));
  return (u + v);
}

int main() {
    printf("Greatest Common Divisor = %i", gcd_iter(115, 230));
}
Posted by: Guest on May-31-2021

Code answers related to "recursion greatest common divisor"

Browse Popular Code Answers by Language