Comparing fractions X00639


Statement
 

pdf   zip   main.cc

html

Write a function

bool c_frac(int n1, int d1, int n2, int d2);

that returns true whenever the fraction n1/d1 is strictly smaller than the fraction n2/d2.

Precondition

d1, d2 > 0.

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

Public test cases
  • Input/Output

    c_frac(0, 3, 0, 3) → no
    c_frac(1, 7, 2, 7) → yes
    c_frac(2, 7, 1, 7) → no
    c_frac(-1, 7, 2, 7) → yes
    c_frac(2, 7, -1, 7) → no
    c_frac(-630, 723, 510, 423) → yes
  • Information
    Author
    Maria Serna
    Language
    English
    Translator
    Maria Serna
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    C++
    User solutions
    C++