fork download
  1. program recursion_euclidalgo;
  2. var
  3. y1:integer;
  4. function receuclid(var a,b:integer):integer;
  5. var
  6. q,r,y,y2,x:integer;
  7. begin
  8. if(b=0) then
  9. begin
  10. receuclid:=0;
  11. y1:=1;
  12. exit;
  13. end;
  14. q:=a div b;
  15. r:=a mod b;
  16. y:=receuclid(b,r);
  17. x:=y1;
  18. y2:=x-y*q;
  19. y1:=y;
  20. receuclid:=y2;
  21.  
  22. end;
  23. var
  24. i,x,y:integer;
  25. begin
  26. readln(x,y);
  27. i:=receuclid(x,y);
  28. writeln('the values of x and y are ',y1,' ',i);
  29. end.
  30.  
stdin
120
23
compilation info
Free Pascal Compiler version 2.2.0 [2009/11/16] for i386
Copyright (c) 1993-2007 by Florian Klaempfl
Target OS: Linux for i386
Compiling prog.pas
Linking prog
29 lines compiled, 0.0 sec
stdout
the values of x and y are -9 47