Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

fraction sum c

/** Struct describing a Fraction */
typedef struct Fraction
{
    int num; // numerator
    int den; // denominator
} Fraction;

Fraction frc_sum(Fraction a, Fraction b)
{
    const int lcm = frc_lcm(a,b);

    Fraction f = {(a.num * lcm/a.den) + (b.num * lcm/b.den), lcm};
    //frc_simplify(&f);

    return f;
}

// IN MAIN
Fraction f1 = {1,3};
Fraction f2 = {1,6};
frc_print(frc_sum(f1, f2));
 
PREVIOUS NEXT
Tagged: #fraction #sum
ADD COMMENT
Topic
Name
5+6 =