/trunk/Examples/ocaml/argout_ref/example.c

# · C · 19 lines · 15 code · 2 blank · 2 comment · 1 complexity · c70f6a122c6778d65541b8e6028684e1 MD5 · raw file

  1. /* File : example.c */
  2. /* Compute the greatest common divisor of positive integers */
  3. int gcd(int x, int y) {
  4. int g;
  5. g = y;
  6. while (x > 0) {
  7. g = x;
  8. x = y % x;
  9. y = g;
  10. }
  11. return g;
  12. }
  13. extern "C" void factor( int &x, int &y ) {
  14. int gcd_xy = gcd( x,y );
  15. x /= gcd_xy;
  16. y /= gcd_xy;
  17. }