Read a rational number (1) P59652


Statement
 

pdf   zip   main.cc

Write a procedure

    void read_rational(int& num, int& den);

to read a rational number given in the form “numerator”/“denominator”, and store these two values in @num@ and @den@, respectively. Additionally, you must remove all common factors from @num@ and @den@. For instance, if the input has

66/12

the values after the call must be @num@ =11= 11 and @den@ =2= 2.

Precondition

11 \le @num@ 109\le 10^9 and 11 \le @den@ 109\le 10^9

Observation

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

Information
Author
Salvador Roura
Language
English
Translator
Salvador Roura
Original language
Catalan
Other languages
Catalan
Official solutions
C++
User solutions
C++