PageRenderTime 538ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C | 19 lines | 15 code | 2 blank | 2 comment | 1 complexity | c70f6a122c6778d65541b8e6028684e1 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  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. }