Question #186334

Write a function named "reduce" that takes two positive integer arguments, call the "number" and "denim" treats them as the numerator and denominator of a fraction and reduce the fraction.that is to say each of the two arguments will be modified by dividing it by the greatest common division of two integers


Expert's answer

#include <iostream>

using namespace std;


int findGCD(int number1, int number2)
{
    if(number2 == 0)
        return number1;
    return findGCD(number2, number1%number2);
}
int reduce(int& number, int& denim)
{
    int gcd = findGCD(number, denim);


    number/=gcd;
    denim/=gcd;
}


int main()
{
    cout << "Enter numerator: ";
    int number;
    cin >> number;


    cout << "Enter denominator: ";
    int denim;
    cin >> denim;


    reduce(number, denim);


    cout << endl << "Reduced fraction" << endl;
    cout << "numerator: " << number << endl;
    cout << "denominator: " << denim << endl;


    cout << endl << endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS