Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

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));
}
 
PREVIOUS NEXT
Tagged: #Greatest #common #divisor #iterative
ADD COMMENT
Topic
Name
1+2 =