Rational numbers (1)

Using the definition

    struct Rational {
        int num, den;
    };

write a function

    Rational rational(int n, int d);

that returns an equivalent rational to nd\frac{n}{d} and “normalized” according to: if the numerator is 0, the denominator is 1; otherwise, the numerator and the denominator do not have any common factor, and the denominator is positive.

Precondition

@d@ 0\neq 0.

Observation

You only need to submit the required classes; your main program will be ignored.

Strictly obey the type definitions of the statement.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:06:17.460Z

© Jutge.org, 2006–2026.
https://jutge.org