23 lines
437 B
C
23 lines
437 B
C
#include <stdio.h>
|
|
|
|
int gcd(int a, int b)
|
|
{
|
|
return (b == 0) ? a : gcd(b, a % b);
|
|
}
|
|
|
|
int show_simplified(int a, int b)
|
|
{
|
|
if (!a || !b) return printf("a, b should not be zero!\n");
|
|
int sign = (a > 0) ^ (b > 0);
|
|
a = (a > 0) ? a : -a;
|
|
b = (b > 0) ? b : -b;
|
|
int d = gcd(a, b);
|
|
return printf("simplified is: %s%d/%d\n", sign ? "-" : "", a / d, b / d);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
show_simplified(123, 333);
|
|
return 0;
|
|
}
|