#include typedef struct rational { int a; int b; } RATIONAL; int gcd(int a, int b) { int r; r = a % b; while ( r != 0 ) { a = b; b = r; r = a % b; } return b; } void reduce(RATIONAL *p) { int c; c = gcd(p->a, p->b); p->a /= c; p->b /= c; } RATIONAL add(RATIONAL x, RATIONAL y) { RATIONAL z; z.a = (x.a * y.b) + (y.a * x.b); z.b = x.b * y.b; reduce(&z); return z; } void print_r(RATIONAL x ) { reduce(&x); printf("%d/%d", x.a, x.b); } void scan_r(RATIONAL *p) { scanf("%d%d", &(p->a), &(p->b)); }