mihainan

Laboratorul 5 - Prob. 4

Nov 3rd, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. /**
  2.  * Problema 4
  3.  * Laboratorul 5 - Seria CC
  4.  */
  5.  
  6. #include<stdio.h>
  7.  
  8. int cmmdc (int a, int b)
  9. {
  10.     while (a != b)
  11.     {
  12.         if (a > b)
  13.             a = a - b;
  14.         if (b > a)
  15.             b = b - a;
  16.     }
  17.     return a;
  18. }
  19.  
  20.  
  21. int cmmmc (int a, int b)
  22. {
  23.     return (a * b / cmmdc (a, b));
  24. }
  25.  
  26.  
  27. int main ()
  28. {
  29.     int mc, x1, y1, x2, y2;
  30.     scanf ("%d%d%d%d", &x1, &y1, &x2, &y2);
  31.     if (y1 != y2)
  32.     {
  33.         mc = cmmmc (y1, y2);
  34.         x1 = x1 * (mc / y1);
  35.         x2 = x2 * (mc / y2);
  36.         y1 = y2 = mc;
  37.     }
  38.     printf ("%d/%d\n%d/%d\n", x1, y1, x2, y2);
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment