Abdulg

Simplify Fractions [C]

Aug 7th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.32 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int LargestCommonDivisor(int a, int b)
  4. {
  5.     while (a > 0)
  6.     {
  7.         if (b > a)
  8.         {
  9.             int Temp = a;
  10.             a = b;
  11.             b = Temp;
  12.         }
  13.         a = a - b;
  14.     }
  15.     return b;
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21.     int a, b, LCD;
  22.     scanf("%d/%d", &a, &b);
  23.     LCD = LargestCommonDivisor(a,b);
  24.     printf("%d/%d\n", LCD, b/LCD);
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment