Advertisement
Guest User

darthvlado

a guest
Nov 24th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.54 KB | None | 0 0
  1. var
  2.   a, b, c, d, bd, n, r, i: integer;
  3.  
  4. function nod(a, b: integer): integer;
  5. begin
  6.   while a <> b do
  7.     if a > b then
  8.       a := a - b else
  9.       b := b - a;
  10.   nod := a; end;
  11.  
  12. begin
  13.   readln(a, b, c, d); write(a, '/', b, '-', c, '/', d, '=');
  14.  
  15.   bd := (b * d) div nod(b, d);
  16.   a := (bd div b) * a;
  17.   c := (bd div d) * c;
  18.   if c > a then c := c - a else c := a - c;
  19.   a := c div bd;c := c - bd * a;
  20.   n := nod(c, bd); c := c div n; bd := bd div n;
  21.  
  22.   if c > a then write('-'); if a <> 0 then write(a); write(c, '/', bd);
  23. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement