struct fraction { int top, bot; }; void set(... ... void print(fraction f) ... int gcd(int a, int b) { for (int i = max(a, b); i >= 1; i -= 1) if (a % i == 0 && b % i == 0) return i; return 1; } void correct(fraction & f) { int d = gcd(f.top, f.bot); f.top /= d; f.bot /= d; } fraction add(fraction x, fraction y) { fraction R; set(R, x.top * y.bot + y.top * x.bot, x.bot * y.bot); correct(R); return R; } int main() { fraction A, B; set(A, 1, 2); // A = 1/2; set(B, 3, 4); // B = 3/4 fraction C = add(A, B); print(C); cout << "\n"; }