Example #1
0
RationalNumber rnDivide(RationalNumber n, RationalNumber n1) {

    RationalNumber reziprok = { n1.denominator, n1.numerator };

    if(!rnIsValid(n) || !rnIsValid(n1) || !rnIsValid(reziprok)) {
        RationalNumber tmp = { 0, 0};
        return tmp;
    }
    return rnNormalize(rnMultiply(n, reziprok));
}
void rncCalcAverage(RationalNumberCollection *c) {

    // Zeiger auf Collection
    RationalNumber (*ptr)[2] = c->rn;

    // Alle Brüche in der Collection zählen und sie summieren
    int i = 0;
    RationalNumber count =  { 0, 1 };
    RationalNumber result = { 0, 1 };
    while(ptr[i][1].numerator > 0) {
        result = rnAdd(result, rnMultiply(ptr[i][0], ptr[i][1]));
        count.numerator += ptr[i][1].numerator;
        i++;
    }

    // Wenn keine Brüche gespeichert
    if (count.numerator == 0) {
        count.numerator = 1;
    }

    // Gekürzte RationalNumber zurückgeben
    c->average = rnShorten(rnDivide(result, count));

}
Example #3
0
RationalNumber rnDivide (RationalNumber r1, RationalNumber r2) {
    RationalNumber inverse = {r2.denominator, r2.numerator};
    return rnMultiply(r1, inverse);
}