Addition of Rational Numbers (2)

  1. Modify your previous exercise so that it works with the following main program.
    
    struct Rational
    {
        int numerator;
        int denominator;
    };
    
    void add(Rational q1, Rational q2, Rational& q3);
    void print(Rational q);
    
    int main()
    {
        const unsigned short N = 5;
        Rational a[N]   = { {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5} };
        Rational b[N] = { {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1} };
        Rational c[N];
        int i;
        for (i=0; i<N; i++)
        {
            add(a[i], b[i], c[i]);
            print(a[i]);
            cout << " + ";
            print(b[i]);
            cout << " = ";
            print(c[i]);
            cout << endl;
        }
        return 0;
    }